psych 5.1.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,9 +32,9 @@ static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
32
32
  *read = 0;
33
33
 
34
34
  if(! NIL_P(string)) {
35
- void * str = (void *)StringValuePtr(string);
36
- *read = (size_t)RSTRING_LEN(string);
37
- memcpy(buf, str, *read);
35
+ void * str = (void *)StringValuePtr(string);
36
+ *read = (size_t)RSTRING_LEN(string);
37
+ memcpy(buf, str, *read);
38
38
  }
39
39
 
40
40
  return 1;
@@ -80,23 +80,23 @@ static VALUE allocate(VALUE klass)
80
80
  static VALUE make_exception(yaml_parser_t * parser, VALUE path)
81
81
  {
82
82
  if (parser->error == YAML_MEMORY_ERROR) {
83
- return rb_eNoMemError;
83
+ return rb_eNoMemError;
84
84
  } else {
85
- size_t line, column;
86
- VALUE ePsychSyntaxError;
85
+ size_t line, column;
86
+ VALUE ePsychSyntaxError;
87
87
 
88
- line = parser->context_mark.line + 1;
89
- column = parser->context_mark.column + 1;
88
+ line = parser->context_mark.line + 1;
89
+ column = parser->context_mark.column + 1;
90
90
 
91
- ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
91
+ ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
92
92
 
93
- return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
94
- path,
95
- SIZET2NUM(line),
96
- SIZET2NUM(column),
97
- SIZET2NUM(parser->problem_offset),
98
- parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
99
- parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
93
+ return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
94
+ path,
95
+ SIZET2NUM(line),
96
+ SIZET2NUM(column),
97
+ SIZET2NUM(parser->problem_offset),
98
+ parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
99
+ parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
100
100
  }
101
101
  }
102
102
 
@@ -108,18 +108,18 @@ static VALUE transcode_string(VALUE src, int * parser_encoding)
108
108
  int source_encoding = rb_enc_get_index(src);
109
109
 
110
110
  if (source_encoding == utf8) {
111
- *parser_encoding = YAML_UTF8_ENCODING;
112
- return src;
111
+ *parser_encoding = YAML_UTF8_ENCODING;
112
+ return src;
113
113
  }
114
114
 
115
115
  if (source_encoding == utf16le) {
116
- *parser_encoding = YAML_UTF16LE_ENCODING;
117
- return src;
116
+ *parser_encoding = YAML_UTF16LE_ENCODING;
117
+ return src;
118
118
  }
119
119
 
120
120
  if (source_encoding == utf16be) {
121
- *parser_encoding = YAML_UTF16BE_ENCODING;
122
- return src;
121
+ *parser_encoding = YAML_UTF16BE_ENCODING;
122
+ return src;
123
123
  }
124
124
 
125
125
  src = rb_str_export_to_enc(src, rb_utf8_encoding());
@@ -138,36 +138,36 @@ static VALUE transcode_io(VALUE src, int * parser_encoding)
138
138
 
139
139
  /* if no encoding is returned, assume ascii8bit. */
140
140
  if (NIL_P(io_external_encoding)) {
141
- io_external_enc_index = rb_ascii8bit_encindex();
141
+ io_external_enc_index = rb_ascii8bit_encindex();
142
142
  } else {
143
- io_external_enc_index = rb_to_encoding_index(io_external_encoding);
143
+ io_external_enc_index = rb_to_encoding_index(io_external_encoding);
144
144
  }
145
145
 
146
146
  /* Treat US-ASCII as utf_8 */
147
147
  if (io_external_enc_index == rb_usascii_encindex()) {
148
- *parser_encoding = YAML_UTF8_ENCODING;
149
- return src;
148
+ *parser_encoding = YAML_UTF8_ENCODING;
149
+ return src;
150
150
  }
151
151
 
152
152
  if (io_external_enc_index == rb_utf8_encindex()) {
153
- *parser_encoding = YAML_UTF8_ENCODING;
154
- return src;
153
+ *parser_encoding = YAML_UTF8_ENCODING;
154
+ return src;
155
155
  }
156
156
 
157
157
  if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
158
- *parser_encoding = YAML_UTF16LE_ENCODING;
159
- return src;
158
+ *parser_encoding = YAML_UTF16LE_ENCODING;
159
+ return src;
160
160
  }
161
161
 
162
162
  if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
163
- *parser_encoding = YAML_UTF16BE_ENCODING;
164
- return src;
163
+ *parser_encoding = YAML_UTF16BE_ENCODING;
164
+ return src;
165
165
  }
166
166
 
167
167
  /* Just guess on ASCII-8BIT */
168
168
  if (io_external_enc_index == rb_ascii8bit_encindex()) {
169
- *parser_encoding = YAML_ANY_ENCODING;
170
- return src;
169
+ *parser_encoding = YAML_ANY_ENCODING;
170
+ return src;
171
171
  }
172
172
 
173
173
  /* If the external encoding is something we don't know how to handle,
@@ -261,238 +261,238 @@ static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
261
261
  yaml_parser_initialize(parser);
262
262
 
263
263
  if (rb_respond_to(yaml, id_read)) {
264
- yaml = transcode_io(yaml, &parser_encoding);
265
- yaml_parser_set_encoding(parser, parser_encoding);
266
- yaml_parser_set_input(parser, io_reader, (void *)yaml);
264
+ yaml = transcode_io(yaml, &parser_encoding);
265
+ yaml_parser_set_encoding(parser, parser_encoding);
266
+ yaml_parser_set_input(parser, io_reader, (void *)yaml);
267
267
  } else {
268
- StringValue(yaml);
269
- yaml = transcode_string(yaml, &parser_encoding);
270
- yaml_parser_set_encoding(parser, parser_encoding);
271
- yaml_parser_set_input_string(
272
- parser,
273
- (const unsigned char *)RSTRING_PTR(yaml),
274
- (size_t)RSTRING_LEN(yaml)
275
- );
268
+ StringValue(yaml);
269
+ yaml = transcode_string(yaml, &parser_encoding);
270
+ yaml_parser_set_encoding(parser, parser_encoding);
271
+ yaml_parser_set_input_string(
272
+ parser,
273
+ (const unsigned char *)RSTRING_PTR(yaml),
274
+ (size_t)RSTRING_LEN(yaml)
275
+ );
276
276
  }
277
277
 
278
278
  while(!done) {
279
- VALUE event_args[5];
280
- VALUE start_line, start_column, end_line, end_column;
281
-
282
- if(parser->error || !yaml_parser_parse(parser, &event)) {
283
- VALUE exception;
284
-
285
- exception = make_exception(parser, path);
286
- yaml_parser_delete(parser);
287
- yaml_parser_initialize(parser);
288
-
289
- rb_exc_raise(exception);
290
- }
291
-
292
- start_line = SIZET2NUM(event.start_mark.line);
293
- start_column = SIZET2NUM(event.start_mark.column);
294
- end_line = SIZET2NUM(event.end_mark.line);
295
- end_column = SIZET2NUM(event.end_mark.column);
296
-
297
- event_args[0] = handler;
298
- event_args[1] = start_line;
299
- event_args[2] = start_column;
300
- event_args[3] = end_line;
301
- event_args[4] = end_column;
302
- rb_protect(protected_event_location, (VALUE)event_args, &state);
303
-
304
- switch(event.type) {
305
- case YAML_STREAM_START_EVENT:
306
- {
307
- VALUE args[2];
308
-
309
- args[0] = handler;
310
- args[1] = INT2NUM(event.data.stream_start.encoding);
311
- rb_protect(protected_start_stream, (VALUE)args, &state);
312
- }
313
- break;
314
- case YAML_DOCUMENT_START_EVENT:
315
- {
316
- VALUE args[4];
317
- /* Get a list of tag directives (if any) */
318
- VALUE tag_directives = rb_ary_new();
319
- /* Grab the document version */
320
- VALUE version = event.data.document_start.version_directive ?
321
- rb_ary_new3(
322
- (long)2,
323
- INT2NUM(event.data.document_start.version_directive->major),
324
- INT2NUM(event.data.document_start.version_directive->minor)
325
- ) : rb_ary_new();
326
-
327
- if(event.data.document_start.tag_directives.start) {
328
- yaml_tag_directive_t *start =
329
- event.data.document_start.tag_directives.start;
330
- yaml_tag_directive_t *end =
331
- event.data.document_start.tag_directives.end;
332
- for(; start != end; start++) {
333
- VALUE handle = Qnil;
334
- VALUE prefix = Qnil;
335
- if(start->handle) {
336
- handle = rb_str_new2((const char *)start->handle);
337
- PSYCH_TRANSCODE(handle, encoding, internal_enc);
338
- }
339
-
340
- if(start->prefix) {
341
- prefix = rb_str_new2((const char *)start->prefix);
342
- PSYCH_TRANSCODE(prefix, encoding, internal_enc);
343
- }
344
-
345
- rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
346
- }
347
- }
348
- args[0] = handler;
349
- args[1] = version;
350
- args[2] = tag_directives;
351
- args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
352
- rb_protect(protected_start_document, (VALUE)args, &state);
353
- }
354
- break;
355
- case YAML_DOCUMENT_END_EVENT:
356
- {
357
- VALUE args[2];
358
-
359
- args[0] = handler;
360
- args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
361
- rb_protect(protected_end_document, (VALUE)args, &state);
362
- }
363
- break;
364
- case YAML_ALIAS_EVENT:
365
- {
366
- VALUE args[2];
367
- VALUE alias = Qnil;
368
- if(event.data.alias.anchor) {
369
- alias = rb_str_new2((const char *)event.data.alias.anchor);
370
- PSYCH_TRANSCODE(alias, encoding, internal_enc);
371
- }
372
-
373
- args[0] = handler;
374
- args[1] = alias;
375
- rb_protect(protected_alias, (VALUE)args, &state);
376
- }
377
- break;
378
- case YAML_SCALAR_EVENT:
379
- {
380
- VALUE args[7];
381
- VALUE anchor = Qnil;
382
- VALUE tag = Qnil;
383
- VALUE plain_implicit, quoted_implicit, style;
384
- VALUE val = rb_str_new(
385
- (const char *)event.data.scalar.value,
386
- (long)event.data.scalar.length
387
- );
388
-
389
- PSYCH_TRANSCODE(val, encoding, internal_enc);
390
-
391
- if(event.data.scalar.anchor) {
392
- anchor = rb_str_new2((const char *)event.data.scalar.anchor);
393
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
394
- }
395
-
396
- if(event.data.scalar.tag) {
397
- tag = rb_str_new2((const char *)event.data.scalar.tag);
398
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
399
- }
400
-
401
- plain_implicit =
402
- event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
403
-
404
- quoted_implicit =
405
- event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
406
-
407
- style = INT2NUM(event.data.scalar.style);
408
-
409
- args[0] = handler;
410
- args[1] = val;
411
- args[2] = anchor;
412
- args[3] = tag;
413
- args[4] = plain_implicit;
414
- args[5] = quoted_implicit;
415
- args[6] = style;
416
- rb_protect(protected_scalar, (VALUE)args, &state);
417
- }
418
- break;
419
- case YAML_SEQUENCE_START_EVENT:
420
- {
421
- VALUE args[5];
422
- VALUE anchor = Qnil;
423
- VALUE tag = Qnil;
424
- VALUE implicit, style;
425
- if(event.data.sequence_start.anchor) {
426
- anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
427
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
428
- }
429
-
430
- tag = Qnil;
431
- if(event.data.sequence_start.tag) {
432
- tag = rb_str_new2((const char *)event.data.sequence_start.tag);
433
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
434
- }
435
-
436
- implicit =
437
- event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
438
-
439
- style = INT2NUM(event.data.sequence_start.style);
440
-
441
- args[0] = handler;
442
- args[1] = anchor;
443
- args[2] = tag;
444
- args[3] = implicit;
445
- args[4] = style;
446
-
447
- rb_protect(protected_start_sequence, (VALUE)args, &state);
448
- }
449
- break;
450
- case YAML_SEQUENCE_END_EVENT:
451
- rb_protect(protected_end_sequence, handler, &state);
452
- break;
453
- case YAML_MAPPING_START_EVENT:
454
- {
455
- VALUE args[5];
456
- VALUE anchor = Qnil;
457
- VALUE tag = Qnil;
458
- VALUE implicit, style;
459
- if(event.data.mapping_start.anchor) {
460
- anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
461
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
462
- }
463
-
464
- if(event.data.mapping_start.tag) {
465
- tag = rb_str_new2((const char *)event.data.mapping_start.tag);
466
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
467
- }
468
-
469
- implicit =
470
- event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
471
-
472
- style = INT2NUM(event.data.mapping_start.style);
473
-
474
- args[0] = handler;
475
- args[1] = anchor;
476
- args[2] = tag;
477
- args[3] = implicit;
478
- args[4] = style;
479
-
480
- rb_protect(protected_start_mapping, (VALUE)args, &state);
481
- }
482
- break;
483
- case YAML_MAPPING_END_EVENT:
484
- rb_protect(protected_end_mapping, handler, &state);
485
- break;
486
- case YAML_NO_EVENT:
487
- rb_protect(protected_empty, handler, &state);
488
- break;
489
- case YAML_STREAM_END_EVENT:
490
- rb_protect(protected_end_stream, handler, &state);
491
- done = 1;
492
- break;
493
- }
494
- yaml_event_delete(&event);
495
- if (state) rb_jump_tag(state);
279
+ VALUE event_args[5];
280
+ VALUE start_line, start_column, end_line, end_column;
281
+
282
+ if(parser->error || !yaml_parser_parse(parser, &event)) {
283
+ VALUE exception;
284
+
285
+ exception = make_exception(parser, path);
286
+ yaml_parser_delete(parser);
287
+ yaml_parser_initialize(parser);
288
+
289
+ rb_exc_raise(exception);
290
+ }
291
+
292
+ start_line = SIZET2NUM(event.start_mark.line);
293
+ start_column = SIZET2NUM(event.start_mark.column);
294
+ end_line = SIZET2NUM(event.end_mark.line);
295
+ end_column = SIZET2NUM(event.end_mark.column);
296
+
297
+ event_args[0] = handler;
298
+ event_args[1] = start_line;
299
+ event_args[2] = start_column;
300
+ event_args[3] = end_line;
301
+ event_args[4] = end_column;
302
+ rb_protect(protected_event_location, (VALUE)event_args, &state);
303
+
304
+ switch(event.type) {
305
+ case YAML_STREAM_START_EVENT:
306
+ {
307
+ VALUE args[2];
308
+
309
+ args[0] = handler;
310
+ args[1] = INT2NUM(event.data.stream_start.encoding);
311
+ rb_protect(protected_start_stream, (VALUE)args, &state);
312
+ }
313
+ break;
314
+ case YAML_DOCUMENT_START_EVENT:
315
+ {
316
+ VALUE args[4];
317
+ /* Get a list of tag directives (if any) */
318
+ VALUE tag_directives = rb_ary_new();
319
+ /* Grab the document version */
320
+ VALUE version = event.data.document_start.version_directive ?
321
+ rb_ary_new3(
322
+ (long)2,
323
+ INT2NUM(event.data.document_start.version_directive->major),
324
+ INT2NUM(event.data.document_start.version_directive->minor)
325
+ ) : rb_ary_new();
326
+
327
+ if(event.data.document_start.tag_directives.start) {
328
+ yaml_tag_directive_t *start =
329
+ event.data.document_start.tag_directives.start;
330
+ yaml_tag_directive_t *end =
331
+ event.data.document_start.tag_directives.end;
332
+ for(; start != end; start++) {
333
+ VALUE handle = Qnil;
334
+ VALUE prefix = Qnil;
335
+ if(start->handle) {
336
+ handle = rb_str_new2((const char *)start->handle);
337
+ PSYCH_TRANSCODE(handle, encoding, internal_enc);
338
+ }
339
+
340
+ if(start->prefix) {
341
+ prefix = rb_str_new2((const char *)start->prefix);
342
+ PSYCH_TRANSCODE(prefix, encoding, internal_enc);
343
+ }
344
+
345
+ rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
346
+ }
347
+ }
348
+ args[0] = handler;
349
+ args[1] = version;
350
+ args[2] = tag_directives;
351
+ args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
352
+ rb_protect(protected_start_document, (VALUE)args, &state);
353
+ }
354
+ break;
355
+ case YAML_DOCUMENT_END_EVENT:
356
+ {
357
+ VALUE args[2];
358
+
359
+ args[0] = handler;
360
+ args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
361
+ rb_protect(protected_end_document, (VALUE)args, &state);
362
+ }
363
+ break;
364
+ case YAML_ALIAS_EVENT:
365
+ {
366
+ VALUE args[2];
367
+ VALUE alias = Qnil;
368
+ if(event.data.alias.anchor) {
369
+ alias = rb_str_new2((const char *)event.data.alias.anchor);
370
+ PSYCH_TRANSCODE(alias, encoding, internal_enc);
371
+ }
372
+
373
+ args[0] = handler;
374
+ args[1] = alias;
375
+ rb_protect(protected_alias, (VALUE)args, &state);
376
+ }
377
+ break;
378
+ case YAML_SCALAR_EVENT:
379
+ {
380
+ VALUE args[7];
381
+ VALUE anchor = Qnil;
382
+ VALUE tag = Qnil;
383
+ VALUE plain_implicit, quoted_implicit, style;
384
+ VALUE val = rb_str_new(
385
+ (const char *)event.data.scalar.value,
386
+ (long)event.data.scalar.length
387
+ );
388
+
389
+ PSYCH_TRANSCODE(val, encoding, internal_enc);
390
+
391
+ if(event.data.scalar.anchor) {
392
+ anchor = rb_str_new2((const char *)event.data.scalar.anchor);
393
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
394
+ }
395
+
396
+ if(event.data.scalar.tag) {
397
+ tag = rb_str_new2((const char *)event.data.scalar.tag);
398
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
399
+ }
400
+
401
+ plain_implicit =
402
+ event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
403
+
404
+ quoted_implicit =
405
+ event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
406
+
407
+ style = INT2NUM(event.data.scalar.style);
408
+
409
+ args[0] = handler;
410
+ args[1] = val;
411
+ args[2] = anchor;
412
+ args[3] = tag;
413
+ args[4] = plain_implicit;
414
+ args[5] = quoted_implicit;
415
+ args[6] = style;
416
+ rb_protect(protected_scalar, (VALUE)args, &state);
417
+ }
418
+ break;
419
+ case YAML_SEQUENCE_START_EVENT:
420
+ {
421
+ VALUE args[5];
422
+ VALUE anchor = Qnil;
423
+ VALUE tag = Qnil;
424
+ VALUE implicit, style;
425
+ if(event.data.sequence_start.anchor) {
426
+ anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
427
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
428
+ }
429
+
430
+ tag = Qnil;
431
+ if(event.data.sequence_start.tag) {
432
+ tag = rb_str_new2((const char *)event.data.sequence_start.tag);
433
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
434
+ }
435
+
436
+ implicit =
437
+ event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
438
+
439
+ style = INT2NUM(event.data.sequence_start.style);
440
+
441
+ args[0] = handler;
442
+ args[1] = anchor;
443
+ args[2] = tag;
444
+ args[3] = implicit;
445
+ args[4] = style;
446
+
447
+ rb_protect(protected_start_sequence, (VALUE)args, &state);
448
+ }
449
+ break;
450
+ case YAML_SEQUENCE_END_EVENT:
451
+ rb_protect(protected_end_sequence, handler, &state);
452
+ break;
453
+ case YAML_MAPPING_START_EVENT:
454
+ {
455
+ VALUE args[5];
456
+ VALUE anchor = Qnil;
457
+ VALUE tag = Qnil;
458
+ VALUE implicit, style;
459
+ if(event.data.mapping_start.anchor) {
460
+ anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
461
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
462
+ }
463
+
464
+ if(event.data.mapping_start.tag) {
465
+ tag = rb_str_new2((const char *)event.data.mapping_start.tag);
466
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
467
+ }
468
+
469
+ implicit =
470
+ event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
471
+
472
+ style = INT2NUM(event.data.mapping_start.style);
473
+
474
+ args[0] = handler;
475
+ args[1] = anchor;
476
+ args[2] = tag;
477
+ args[3] = implicit;
478
+ args[4] = style;
479
+
480
+ rb_protect(protected_start_mapping, (VALUE)args, &state);
481
+ }
482
+ break;
483
+ case YAML_MAPPING_END_EVENT:
484
+ rb_protect(protected_end_mapping, handler, &state);
485
+ break;
486
+ case YAML_NO_EVENT:
487
+ rb_protect(protected_empty, handler, &state);
488
+ break;
489
+ case YAML_STREAM_END_EVENT:
490
+ rb_protect(protected_end_stream, handler, &state);
491
+ done = 1;
492
+ break;
493
+ }
494
+ yaml_event_delete(&event);
495
+ if (state) rb_jump_tag(state);
496
496
  }
497
497
 
498
498
  return self;
@@ -562,4 +562,3 @@ void Init_psych_parser(void)
562
562
  id_end_mapping = rb_intern("end_mapping");
563
563
  id_event_location = rb_intern("event_location");
564
564
  }
565
- /* vim: set noet sws=4 sw=4: */
@@ -36,4 +36,3 @@ void Init_psych_to_ruby(void)
36
36
  rb_define_private_method(cPsychVisitorsToRuby, "build_exception", build_exception, 2);
37
37
  rb_define_private_method(class_loader, "path2class", path2class, 1);
38
38
  }
39
- /* vim: set noet sws=4 sw=4: */
@@ -9,4 +9,3 @@ void Init_psych_yaml_tree(void)
9
9
  VALUE visitor = rb_define_class_under(visitors, "Visitor", rb_cObject);
10
10
  cPsychVisitorsYamlTree = rb_define_class_under(visitors, "YAMLTree", visitor);
11
11
  }
12
- /* vim: set noet sws=4 sw=4: */
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'stringio'
3
2
  require_relative '../class_loader'
4
3
  require_relative '../scalar_scanner'
5
4
 
@@ -56,6 +55,7 @@ module Psych
56
55
  #
57
56
  # See also Psych::Visitors::Emitter
58
57
  def yaml io = nil, options = {}
58
+ require "stringio"
59
59
  real_io = io || StringIO.new(''.encode('utf-8'))
60
60
 
61
61
  Visitors::Emitter.new(real_io, options).accept self
@@ -11,18 +11,18 @@ module Psych
11
11
  # Base 60, [-+]inf and NaN are handled separately
12
12
  FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
13
13
 
14
- # Taken from http://yaml.org/type/int.html
15
- INTEGER_STRICT = /^(?:[-+]?0b[0-1_]+ (?# base 2)
16
- |[-+]?0[0-7_]+ (?# base 8)
17
- |[-+]?(0|[1-9][0-9_]*) (?# base 10)
18
- |[-+]?0x[0-9a-fA-F_]+ (?# base 16))$/x
14
+ # Taken from http://yaml.org/type/int.html and modified to ensure at least one numerical symbol exists
15
+ INTEGER_STRICT = /^(?:[-+]?0b[_]*[0-1][0-1_]* (?# base 2)
16
+ |[-+]?0[_]*[0-7][0-7_]* (?# base 8)
17
+ |[-+]?(0|[1-9][0-9_]*) (?# base 10)
18
+ |[-+]?0x[_]*[0-9a-fA-F][0-9a-fA-F_]* (?# base 16))$/x
19
19
 
20
20
  # Same as above, but allows commas.
21
21
  # Not to YML spec, but kept for backwards compatibility
22
- INTEGER_LEGACY = /^(?:[-+]?0b[0-1_,]+ (?# base 2)
23
- |[-+]?0[0-7_,]+ (?# base 8)
22
+ INTEGER_LEGACY = /^(?:[-+]?0b[_,]*[0-1][0-1_,]* (?# base 2)
23
+ |[-+]?0[_,]*[0-7][0-7_,]* (?# base 8)
24
24
  |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
25
- |[-+]?0x[0-9a-fA-F_,]+ (?# base 16))$/x
25
+ |[-+]?0x[_,]*[0-9a-fA-F][0-9a-fA-F_,]* (?# base 16))$/x
26
26
 
27
27
  attr_reader :class_loader
28
28
 
@@ -61,7 +61,6 @@ module Psych
61
61
  string
62
62
  end
63
63
  elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
64
- require 'date'
65
64
  begin
66
65
  class_loader.date.strptime(string, '%F', Date::GREGORIAN)
67
66
  rescue ArgumentError