psych 5.1.2 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39bdb85aafa27b992e7e8db6905f6e1bc52976bbfc3f71e0ce1adee552a89682
4
- data.tar.gz: a8d566aa3e16cde752a41ffdb5990af2b2d4f7082ad8774dbd3a8250636fef20
3
+ metadata.gz: 270858d5e7932bd2a8c72d6861566ebfef58a7c2bea4acd2635a3aa4246b89cc
4
+ data.tar.gz: 20f230ccc6bc96cb1bb54fe77263b4545aad9a5028023fc6b2c13dc6e4934ca4
5
5
  SHA512:
6
- metadata.gz: ca436b4d85c8c931bfc9b05d2f16a52f03d01f65c5d708419f75ce926ba55ef9aa4af95a811fec0309773ec6f8963002ffa5ead5cc2f69e1666d3759f24a688b
7
- data.tar.gz: bc2aabe53f58a0eb15fed477c96767bc4267ce6bd1f929010c580a0891fdbe28517fdf030a09356dd9b84000c60e1fe7d403d2d9414b5b3a7db8bfa152f5ba5a
6
+ metadata.gz: dc1a496280c8d941f7d87924279dfc4e95b23046d0d7c5520fac4ff4c31eb6f2d4f0254bf73ea60f5a0974b8e03ad7005944ce569344908e0835691d1c5d7cba
7
+ data.tar.gz: c0018b3e09a66ce9aff01c1d1546b2cae40f15ea2e47045ecccb5eedabdd60f5ca8f59f91eb1e3f5c6540e6dcf0c8b0b47d3518de75ac9ae4e0a6ad5b3c86b3e
data/ext/psych/psych.c CHANGED
@@ -23,7 +23,7 @@ VALUE mPsych;
23
23
  void Init_psych(void)
24
24
  {
25
25
  #ifdef HAVE_RB_EXT_RACTOR_SAFE
26
- RB_EXT_RACTOR_SAFE(true);
26
+ RB_EXT_RACTOR_SAFE(true);
27
27
  #endif
28
28
  mPsych = rb_define_module("Psych");
29
29
 
@@ -17,7 +17,7 @@ static ID id_canonical;
17
17
  static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
18
18
  {
19
19
  if(!yaml_emitter_emit(emitter, event))
20
- rb_raise(rb_eRuntimeError, "%s", emitter->problem);
20
+ rb_raise(rb_eRuntimeError, "%s", emitter->problem);
21
21
  }
22
22
 
23
23
  static int writer(void *ctx, unsigned char *buffer, size_t size)
@@ -82,13 +82,13 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
82
82
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
83
83
 
84
84
  if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
85
- line_width = rb_funcall(options, id_line_width, 0);
86
- indent = rb_funcall(options, id_indentation, 0);
87
- canonical = rb_funcall(options, id_canonical, 0);
85
+ line_width = rb_funcall(options, id_line_width, 0);
86
+ indent = rb_funcall(options, id_indentation, 0);
87
+ canonical = rb_funcall(options, id_canonical, 0);
88
88
 
89
- yaml_emitter_set_width(emitter, NUM2INT(line_width));
90
- yaml_emitter_set_indent(emitter, NUM2INT(indent));
91
- yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
89
+ yaml_emitter_set_width(emitter, NUM2INT(line_width));
90
+ yaml_emitter_set_indent(emitter, NUM2INT(indent));
91
+ yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
92
92
  }
93
93
 
94
94
  rb_ivar_set(self, id_io, io);
@@ -136,84 +136,118 @@ static VALUE end_stream(VALUE self)
136
136
  return self;
137
137
  }
138
138
 
139
- /* call-seq: emitter.start_document(version, tags, implicit)
140
- *
141
- * Start a document emission with YAML +version+, +tags+, and an +implicit+
142
- * start.
143
- *
144
- * See Psych::Handler#start_document
145
- */
146
- static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
139
+ struct start_document_data {
140
+ VALUE self;
141
+ VALUE version;
142
+ VALUE tags;
143
+ VALUE imp;
144
+
145
+ yaml_tag_directive_t * head;
146
+ };
147
+
148
+ static VALUE start_document_try(VALUE d)
147
149
  {
150
+ struct start_document_data * data = (struct start_document_data *)d;
151
+ VALUE self = data->self;
152
+ VALUE version = data->version;
153
+ VALUE tags = data->tags;
154
+ VALUE imp = data->imp;
155
+
148
156
  yaml_emitter_t * emitter;
149
- yaml_tag_directive_t * head = NULL;
150
157
  yaml_tag_directive_t * tail = NULL;
151
158
  yaml_event_t event;
152
159
  yaml_version_directive_t version_directive;
153
160
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
154
161
 
155
-
156
162
  Check_Type(version, T_ARRAY);
157
163
 
158
164
  if(RARRAY_LEN(version) > 0) {
159
- VALUE major = rb_ary_entry(version, (long)0);
160
- VALUE minor = rb_ary_entry(version, (long)1);
165
+ VALUE major = rb_ary_entry(version, (long)0);
166
+ VALUE minor = rb_ary_entry(version, (long)1);
161
167
 
162
- version_directive.major = NUM2INT(major);
163
- version_directive.minor = NUM2INT(minor);
168
+ version_directive.major = NUM2INT(major);
169
+ version_directive.minor = NUM2INT(minor);
164
170
  }
165
171
 
166
172
  if(RTEST(tags)) {
167
- long i = 0;
168
- long len;
169
- rb_encoding * encoding = rb_utf8_encoding();
170
-
171
- Check_Type(tags, T_ARRAY);
172
-
173
- len = RARRAY_LEN(tags);
174
- head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
175
- tail = head;
176
-
177
- for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
178
- VALUE tuple = RARRAY_AREF(tags, i);
179
- VALUE name;
180
- VALUE value;
181
-
182
- Check_Type(tuple, T_ARRAY);
183
-
184
- if(RARRAY_LEN(tuple) < 2) {
185
- xfree(head);
186
- rb_raise(rb_eRuntimeError, "tag tuple must be of length 2");
187
- }
188
- name = RARRAY_AREF(tuple, 0);
189
- value = RARRAY_AREF(tuple, 1);
190
- StringValue(name);
191
- StringValue(value);
192
- name = rb_str_export_to_enc(name, encoding);
193
- value = rb_str_export_to_enc(value, encoding);
194
-
195
- tail->handle = (yaml_char_t *)StringValueCStr(name);
196
- tail->prefix = (yaml_char_t *)StringValueCStr(value);
197
-
198
- tail++;
199
- }
173
+ long i = 0;
174
+ long len;
175
+ rb_encoding * encoding = rb_utf8_encoding();
176
+
177
+ Check_Type(tags, T_ARRAY);
178
+
179
+ len = RARRAY_LEN(tags);
180
+ data->head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
181
+ tail = data->head;
182
+
183
+ for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
184
+ VALUE tuple = RARRAY_AREF(tags, i);
185
+ VALUE name;
186
+ VALUE value;
187
+
188
+ Check_Type(tuple, T_ARRAY);
189
+
190
+ if(RARRAY_LEN(tuple) < 2) {
191
+ rb_raise(rb_eRuntimeError, "tag tuple must be of length 2");
192
+ }
193
+
194
+ name = RARRAY_AREF(tuple, 0);
195
+ value = RARRAY_AREF(tuple, 1);
196
+ StringValue(name);
197
+ StringValue(value);
198
+ name = rb_str_export_to_enc(name, encoding);
199
+ value = rb_str_export_to_enc(value, encoding);
200
+
201
+ tail->handle = (yaml_char_t *)StringValueCStr(name);
202
+ tail->prefix = (yaml_char_t *)StringValueCStr(value);
203
+
204
+ tail++;
205
+ }
200
206
  }
201
207
 
202
208
  yaml_document_start_event_initialize(
203
- &event,
204
- (RARRAY_LEN(version) > 0) ? &version_directive : NULL,
205
- head,
206
- tail,
207
- imp ? 1 : 0
208
- );
209
+ &event,
210
+ (RARRAY_LEN(version) > 0) ? &version_directive : NULL,
211
+ data->head,
212
+ tail,
213
+ imp ? 1 : 0
214
+ );
209
215
 
210
216
  emit(emitter, &event);
211
217
 
212
- if(head) xfree(head);
213
-
214
218
  return self;
215
219
  }
216
220
 
221
+ static VALUE start_document_ensure(VALUE d)
222
+ {
223
+ struct start_document_data * data = (struct start_document_data *)d;
224
+
225
+ xfree(data->head);
226
+
227
+ return Qnil;
228
+ }
229
+
230
+ /* call-seq: emitter.start_document(version, tags, implicit)
231
+ *
232
+ * Start a document emission with YAML +version+, +tags+, and an +implicit+
233
+ * start.
234
+ *
235
+ * See Psych::Handler#start_document
236
+ */
237
+ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
238
+ {
239
+ struct start_document_data data = {
240
+ .self = self,
241
+ .version = version,
242
+ .tags = tags,
243
+ .imp = imp,
244
+
245
+ .head = NULL,
246
+ };
247
+
248
+ return rb_ensure(start_document_try, (VALUE)&data, start_document_ensure, (VALUE)&data);
249
+ }
250
+
217
251
  /* call-seq: emitter.end_document(implicit)
218
252
  *
219
253
  * End a document emission with an +implicit+ ending.
@@ -241,14 +275,14 @@ static VALUE end_document(VALUE self, VALUE imp)
241
275
  * See Psych::Handler#scalar
242
276
  */
243
277
  static VALUE scalar(
244
- VALUE self,
245
- VALUE value,
246
- VALUE anchor,
247
- VALUE tag,
248
- VALUE plain,
249
- VALUE quoted,
250
- VALUE style
251
- ) {
278
+ VALUE self,
279
+ VALUE value,
280
+ VALUE anchor,
281
+ VALUE tag,
282
+ VALUE plain,
283
+ VALUE quoted,
284
+ VALUE style
285
+ ) {
252
286
  yaml_emitter_t * emitter;
253
287
  yaml_event_t event;
254
288
  rb_encoding *encoding;
@@ -261,25 +295,25 @@ static VALUE scalar(
261
295
  value = rb_str_export_to_enc(value, encoding);
262
296
 
263
297
  if(!NIL_P(anchor)) {
264
- Check_Type(anchor, T_STRING);
265
- anchor = rb_str_export_to_enc(anchor, encoding);
298
+ Check_Type(anchor, T_STRING);
299
+ anchor = rb_str_export_to_enc(anchor, encoding);
266
300
  }
267
301
 
268
302
  if(!NIL_P(tag)) {
269
- Check_Type(tag, T_STRING);
270
- tag = rb_str_export_to_enc(tag, encoding);
303
+ Check_Type(tag, T_STRING);
304
+ tag = rb_str_export_to_enc(tag, encoding);
271
305
  }
272
306
 
273
307
  yaml_scalar_event_initialize(
274
- &event,
275
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
276
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
277
- (yaml_char_t*)StringValuePtr(value),
278
- (int)RSTRING_LEN(value),
279
- plain ? 1 : 0,
280
- quoted ? 1 : 0,
281
- (yaml_scalar_style_t)NUM2INT(style)
282
- );
308
+ &event,
309
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
310
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
311
+ (yaml_char_t*)StringValuePtr(value),
312
+ (int)RSTRING_LEN(value),
313
+ plain ? 1 : 0,
314
+ quoted ? 1 : 0,
315
+ (yaml_scalar_style_t)NUM2INT(style)
316
+ );
283
317
 
284
318
  emit(emitter, &event);
285
319
 
@@ -294,36 +328,36 @@ static VALUE scalar(
294
328
  * See Psych::Handler#start_sequence
295
329
  */
296
330
  static VALUE start_sequence(
297
- VALUE self,
298
- VALUE anchor,
299
- VALUE tag,
300
- VALUE implicit,
301
- VALUE style
302
- ) {
331
+ VALUE self,
332
+ VALUE anchor,
333
+ VALUE tag,
334
+ VALUE implicit,
335
+ VALUE style
336
+ ) {
303
337
  yaml_emitter_t * emitter;
304
338
  yaml_event_t event;
305
339
 
306
340
  rb_encoding * encoding = rb_utf8_encoding();
307
341
 
308
342
  if(!NIL_P(anchor)) {
309
- Check_Type(anchor, T_STRING);
310
- anchor = rb_str_export_to_enc(anchor, encoding);
343
+ Check_Type(anchor, T_STRING);
344
+ anchor = rb_str_export_to_enc(anchor, encoding);
311
345
  }
312
346
 
313
347
  if(!NIL_P(tag)) {
314
- Check_Type(tag, T_STRING);
315
- tag = rb_str_export_to_enc(tag, encoding);
348
+ Check_Type(tag, T_STRING);
349
+ tag = rb_str_export_to_enc(tag, encoding);
316
350
  }
317
351
 
318
352
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
319
353
 
320
354
  yaml_sequence_start_event_initialize(
321
- &event,
322
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
323
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
324
- implicit ? 1 : 0,
325
- (yaml_sequence_style_t)NUM2INT(style)
326
- );
355
+ &event,
356
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
357
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
358
+ implicit ? 1 : 0,
359
+ (yaml_sequence_style_t)NUM2INT(style)
360
+ );
327
361
 
328
362
  emit(emitter, &event);
329
363
 
@@ -357,12 +391,12 @@ static VALUE end_sequence(VALUE self)
357
391
  * See Psych::Handler#start_mapping
358
392
  */
359
393
  static VALUE start_mapping(
360
- VALUE self,
361
- VALUE anchor,
362
- VALUE tag,
363
- VALUE implicit,
364
- VALUE style
365
- ) {
394
+ VALUE self,
395
+ VALUE anchor,
396
+ VALUE tag,
397
+ VALUE implicit,
398
+ VALUE style
399
+ ) {
366
400
  yaml_emitter_t * emitter;
367
401
  yaml_event_t event;
368
402
  rb_encoding *encoding;
@@ -372,22 +406,22 @@ static VALUE start_mapping(
372
406
  encoding = rb_utf8_encoding();
373
407
 
374
408
  if(!NIL_P(anchor)) {
375
- Check_Type(anchor, T_STRING);
376
- anchor = rb_str_export_to_enc(anchor, encoding);
409
+ Check_Type(anchor, T_STRING);
410
+ anchor = rb_str_export_to_enc(anchor, encoding);
377
411
  }
378
412
 
379
413
  if(!NIL_P(tag)) {
380
- Check_Type(tag, T_STRING);
381
- tag = rb_str_export_to_enc(tag, encoding);
414
+ Check_Type(tag, T_STRING);
415
+ tag = rb_str_export_to_enc(tag, encoding);
382
416
  }
383
417
 
384
418
  yaml_mapping_start_event_initialize(
385
- &event,
386
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
387
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
388
- implicit ? 1 : 0,
389
- (yaml_mapping_style_t)NUM2INT(style)
390
- );
419
+ &event,
420
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
421
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
422
+ implicit ? 1 : 0,
423
+ (yaml_mapping_style_t)NUM2INT(style)
424
+ );
391
425
 
392
426
  emit(emitter, &event);
393
427
 
@@ -426,14 +460,14 @@ static VALUE alias(VALUE self, VALUE anchor)
426
460
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
427
461
 
428
462
  if(!NIL_P(anchor)) {
429
- Check_Type(anchor, T_STRING);
430
- anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
463
+ Check_Type(anchor, T_STRING);
464
+ anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
431
465
  }
432
466
 
433
467
  yaml_alias_event_initialize(
434
- &event,
435
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
436
- );
468
+ &event,
469
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
470
+ );
437
471
 
438
472
  emit(emitter, &event);
439
473
 
@@ -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;
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '5.1.2'
5
+ VERSION = '5.2.1'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
8
  DEFAULT_SNAKEYAML_VERSION = '2.7'.freeze
@@ -36,7 +36,7 @@ module Psych
36
36
 
37
37
  unless @domain_types.empty? || !target.tag
38
38
  key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
39
- key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
39
+ key = "tag:#{key}" unless key.match?(/^(?:tag:|x-private)/)
40
40
 
41
41
  if @domain_types.key? key
42
42
  value, block = @domain_types[key]
@@ -79,7 +79,6 @@ module Psych
79
79
  class_loader.big_decimal._load o.value
80
80
  when "!ruby/object:DateTime"
81
81
  class_loader.date_time
82
- require 'date' unless defined? DateTime
83
82
  t = @ss.parse_time(o.value)
84
83
  DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
85
84
  (t.subsec/86400)
@@ -17,19 +17,15 @@ module Psych
17
17
  def initialize
18
18
  @obj_to_id = {}.compare_by_identity
19
19
  @obj_to_node = {}.compare_by_identity
20
- @targets = []
21
20
  @counter = 0
22
21
  end
23
22
 
24
23
  def register target, node
25
- @targets << target
26
24
  @obj_to_node[target] = node
27
25
  end
28
26
 
29
27
  def key? target
30
28
  @obj_to_node.key? target
31
- rescue NoMethodError
32
- false
33
29
  end
34
30
 
35
31
  def id_for target
@@ -69,6 +65,7 @@ module Psych
69
65
  fail(ArgumentError, "Invalid line_width #{@line_width}, must be non-negative or -1 for unlimited.")
70
66
  end
71
67
  end
68
+ @stringify_names = options[:stringify_names]
72
69
  @coders = []
73
70
 
74
71
  @dispatch_cache = Hash.new do |h,klass|
@@ -264,20 +261,20 @@ module Psych
264
261
  style = Nodes::Scalar::LITERAL
265
262
  plain = false
266
263
  quote = false
267
- elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
264
+ elsif o.match?(/\n(?!\Z)/) # match \n except blank line at the end of string
268
265
  style = Nodes::Scalar::LITERAL
269
266
  elsif o == '<<'
270
267
  style = Nodes::Scalar::SINGLE_QUOTED
271
268
  tag = 'tag:yaml.org,2002:str'
272
269
  plain = false
273
270
  quote = false
274
- elsif o == 'y' || o == 'n'
271
+ elsif o == 'y' || o == 'Y' || o == 'n' || o == 'N'
275
272
  style = Nodes::Scalar::DOUBLE_QUOTED
276
273
  elsif @line_width && o.length > @line_width
277
274
  style = Nodes::Scalar::FOLDED
278
- elsif o =~ /^[^[:word:]][^"]*$/
275
+ elsif o.match?(/^[^[:word:]][^"]*$/)
279
276
  style = Nodes::Scalar::DOUBLE_QUOTED
280
- elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
277
+ elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/.match?(o)
281
278
  style = Nodes::Scalar::SINGLE_QUOTED
282
279
  end
283
280
 
@@ -327,7 +324,7 @@ module Psych
327
324
  if o.class == ::Hash
328
325
  register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
329
326
  o.each do |k,v|
330
- accept k
327
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
331
328
  accept v
332
329
  end
333
330
  @emitter.end_mapping
@@ -340,7 +337,7 @@ module Psych
340
337
  register(o, @emitter.start_mapping(nil, '!set', false, Psych::Nodes::Mapping::BLOCK))
341
338
 
342
339
  o.each do |k,v|
343
- accept k
340
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
344
341
  accept v
345
342
  end
346
343
 
data/lib/psych.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'date'
3
+
2
4
  require_relative 'psych/versions'
3
5
  case RUBY_ENGINE
4
6
  when 'jruby'
@@ -340,7 +342,7 @@ module Psych
340
342
  # provided, the object contained in the first document will be returned.
341
343
  # +filename+ will be used in the exception message if any exception
342
344
  # is raised while parsing. If +yaml+ is empty, it returns
343
- # the specified +fallback+ return value, which defaults to +false+.
345
+ # the specified +fallback+ return value, which defaults to +nil+.
344
346
  #
345
347
  # Raises a Psych::SyntaxError when a YAML syntax error is detected.
346
348
  #
@@ -479,6 +481,7 @@ module Psych
479
481
  #
480
482
  # Default: <tt>2</tt>.
481
483
  # [<tt>:line_width</tt>] Max character to wrap line at.
484
+ # For unlimited line width use <tt>-1</tt>.
482
485
  #
483
486
  # Default: <tt>0</tt> (meaning "wrap at 81").
484
487
  # [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
@@ -489,6 +492,10 @@ module Psych
489
492
  #
490
493
  # Default: <tt>false</tt>.
491
494
  #
495
+ # [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
496
+ #
497
+ # Default: <tt>false</tt>.
498
+ #
492
499
  # Example:
493
500
  #
494
501
  # # Dump an array, get back a YAML string
@@ -502,6 +509,9 @@ module Psych
502
509
  #
503
510
  # # Dump an array to an IO with indentation set
504
511
  # Psych.dump(['a', ['b']], StringIO.new, indentation: 3)
512
+ #
513
+ # # Dump hash with symbol keys as string
514
+ # Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
505
515
  def self.dump o, io = nil, options = {}
506
516
  if Hash === io
507
517
  options = io
@@ -552,6 +562,7 @@ module Psych
552
562
  #
553
563
  # Default: <tt>2</tt>.
554
564
  # [<tt>:line_width</tt>] Max character to wrap line at.
565
+ # For unlimited line width use <tt>-1</tt>.
555
566
  #
556
567
  # Default: <tt>0</tt> (meaning "wrap at 81").
557
568
  # [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
@@ -562,6 +573,10 @@ module Psych
562
573
  #
563
574
  # Default: <tt>false</tt>.
564
575
  #
576
+ # [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
577
+ #
578
+ # Default: <tt>false</tt>.
579
+ #
565
580
  # Example:
566
581
  #
567
582
  # # Dump an array, get back a YAML string
@@ -575,6 +590,9 @@ module Psych
575
590
  #
576
591
  # # Dump an array to an IO with indentation set
577
592
  # Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
593
+ #
594
+ # # Dump hash with symbol keys as string
595
+ # Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
578
596
  def self.safe_dump o, io = nil, options = {}
579
597
  if Hash === io
580
598
  options = io
@@ -653,7 +671,7 @@ module Psych
653
671
  ###
654
672
  # Safely loads the document contained in +filename+. Returns the yaml contained in
655
673
  # +filename+ as a Ruby object, or if the file is empty, it returns
656
- # the specified +fallback+ return value, which defaults to +false+.
674
+ # the specified +fallback+ return value, which defaults to +nil+.
657
675
  # See safe_load for options.
658
676
  def self.safe_load_file filename, **kwargs
659
677
  File.open(filename, 'r:bom|utf-8') { |f|
@@ -664,7 +682,7 @@ module Psych
664
682
  ###
665
683
  # Loads the document contained in +filename+. Returns the yaml contained in
666
684
  # +filename+ as a Ruby object, or if the file is empty, it returns
667
- # the specified +fallback+ return value, which defaults to +false+.
685
+ # the specified +fallback+ return value, which defaults to +nil+.
668
686
  # See load for options.
669
687
  def self.load_file filename, **kwargs
670
688
  File.open(filename, 'r:bom|utf-8') { |f|
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  - SHIBATA Hiroshi
9
9
  - Charles Oliver Nutter
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-12-19 00:00:00.000000000 Z
13
+ date: 2024-12-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: stringio
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: date
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
29
43
  description: |
30
44
  Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
31
45
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
@@ -97,7 +111,8 @@ licenses:
97
111
  - MIT
98
112
  metadata:
99
113
  msys2_mingw_dependencies: libyaml
100
- post_install_message:
114
+ changelog_uri: https://github.com/ruby/psych/releases
115
+ post_install_message:
101
116
  rdoc_options:
102
117
  - "--main"
103
118
  - README.md
@@ -114,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
129
  - !ruby/object:Gem::Version
115
130
  version: '0'
116
131
  requirements: []
117
- rubygems_version: 3.5.1
118
- signing_key:
132
+ rubygems_version: 3.5.11
133
+ signing_key:
119
134
  specification_version: 4
120
135
  summary: Psych is a YAML parser and emitter
121
136
  test_files: []