psych 5.1.2 → 5.2.1
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.
- checksums.yaml +4 -4
- data/ext/psych/psych.c +1 -1
- data/ext/psych/psych_emitter.c +154 -120
- data/ext/psych/psych_parser.c +262 -262
- data/lib/psych/nodes/node.rb +1 -1
- data/lib/psych/scalar_scanner.rb +8 -9
- data/lib/psych/versions.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +1 -2
- data/lib/psych/visitors/yaml_tree.rb +7 -10
- data/lib/psych.rb +21 -3
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 270858d5e7932bd2a8c72d6861566ebfef58a7c2bea4acd2635a3aa4246b89cc
|
4
|
+
data.tar.gz: 20f230ccc6bc96cb1bb54fe77263b4545aad9a5028023fc6b2c13dc6e4934ca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc1a496280c8d941f7d87924279dfc4e95b23046d0d7c5520fac4ff4c31eb6f2d4f0254bf73ea60f5a0974b8e03ad7005944ce569344908e0835691d1c5d7cba
|
7
|
+
data.tar.gz: c0018b3e09a66ce9aff01c1d1546b2cae40f15ea2e47045ecccb5eedabdd60f5ca8f59f91eb1e3f5c6540e6dcf0c8b0b47d3518de75ac9ae4e0a6ad5b3c86b3e
|
data/ext/psych/psych.c
CHANGED
data/ext/psych/psych_emitter.c
CHANGED
@@ -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
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
160
|
-
|
165
|
+
VALUE major = rb_ary_entry(version, (long)0);
|
166
|
+
VALUE minor = rb_ary_entry(version, (long)1);
|
161
167
|
|
162
|
-
|
163
|
-
|
168
|
+
version_directive.major = NUM2INT(major);
|
169
|
+
version_directive.minor = NUM2INT(minor);
|
164
170
|
}
|
165
171
|
|
166
172
|
if(RTEST(tags)) {
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
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
|
-
|
265
|
-
|
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
|
-
|
270
|
-
|
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
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
310
|
-
|
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
|
-
|
315
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
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
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
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
|
-
|
376
|
-
|
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
|
-
|
381
|
-
|
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
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
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
|
-
|
430
|
-
|
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
|
-
|
435
|
-
|
436
|
-
|
468
|
+
&event,
|
469
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
|
470
|
+
);
|
437
471
|
|
438
472
|
emit(emitter, &event);
|
439
473
|
|
data/ext/psych/psych_parser.c
CHANGED
@@ -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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
83
|
+
return rb_eNoMemError;
|
84
84
|
} else {
|
85
|
-
|
86
|
-
|
85
|
+
size_t line, column;
|
86
|
+
VALUE ePsychSyntaxError;
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
line = parser->context_mark.line + 1;
|
89
|
+
column = parser->context_mark.column + 1;
|
90
90
|
|
91
|
-
|
91
|
+
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
112
|
-
|
111
|
+
*parser_encoding = YAML_UTF8_ENCODING;
|
112
|
+
return src;
|
113
113
|
}
|
114
114
|
|
115
115
|
if (source_encoding == utf16le) {
|
116
|
-
|
117
|
-
|
116
|
+
*parser_encoding = YAML_UTF16LE_ENCODING;
|
117
|
+
return src;
|
118
118
|
}
|
119
119
|
|
120
120
|
if (source_encoding == utf16be) {
|
121
|
-
|
122
|
-
|
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
|
-
|
141
|
+
io_external_enc_index = rb_ascii8bit_encindex();
|
142
142
|
} else {
|
143
|
-
|
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
|
-
|
149
|
-
|
148
|
+
*parser_encoding = YAML_UTF8_ENCODING;
|
149
|
+
return src;
|
150
150
|
}
|
151
151
|
|
152
152
|
if (io_external_enc_index == rb_utf8_encindex()) {
|
153
|
-
|
154
|
-
|
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
|
-
|
159
|
-
|
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
|
-
|
164
|
-
|
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
|
-
|
170
|
-
|
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
|
-
|
265
|
-
|
266
|
-
|
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
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
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;
|
data/lib/psych/nodes/node.rb
CHANGED
@@ -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
|
data/lib/psych/scalar_scanner.rb
CHANGED
@@ -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_]
|
16
|
-
|[-+]?0[0-7_]
|
17
|
-
|[-+]?(0|[1-9][0-9_]*)
|
18
|
-
|[-+]?0x[0-9a-fA-F_]
|
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_,]
|
23
|
-
|[-+]?0[0-7_,]
|
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_,]
|
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
|
data/lib/psych/versions.rb
CHANGED
@@ -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
|
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
|
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
|
275
|
+
elsif o.match?(/^[^[:word:]][^"]*$/)
|
279
276
|
style = Nodes::Scalar::DOUBLE_QUOTED
|
280
|
-
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]
|
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 +
|
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 +
|
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 +
|
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
|
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:
|
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
|
-
|
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.
|
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: []
|