psych 5.1.2 → 5.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +10 -9
- data/lib/psych/versions.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +1 -1
- data/lib/psych/visitors/yaml_tree.rb +7 -10
- data/lib/psych.rb +19 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5367e16c44c35843d42d82bdcdf7680efb1de2aef57c200b9f3821f5e897d762
|
4
|
+
data.tar.gz: 199c8a5d96470ea35bff68db0564a161b651e925f65913dfbfad57b3fd072f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d09e7f598210f93780807356f9dfa306fa103eabb022609fb0c566f96faf875681928d441bdd14e4d00fc36bfa12c8892e599073b65fa7769acdb26b9670624
|
7
|
+
data.tar.gz: a4e7ba9cc790f49ef0c683881c5ebd07b568ed236fb42b2d27b7d85401e91207a8a11e518a490ca1fbe92c48396dc71fc84bcc02713977e6f9993279d2e2c782
|
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
@@ -4,6 +4,8 @@ module Psych
|
|
4
4
|
###
|
5
5
|
# Scan scalars for built in types
|
6
6
|
class ScalarScanner
|
7
|
+
autoload :Date, "date"
|
8
|
+
|
7
9
|
# Taken from http://yaml.org/type/timestamp.html
|
8
10
|
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/
|
9
11
|
|
@@ -11,18 +13,18 @@ module Psych
|
|
11
13
|
# Base 60, [-+]inf and NaN are handled separately
|
12
14
|
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
|
13
15
|
|
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_]
|
16
|
+
# Taken from http://yaml.org/type/int.html and modified to ensure at least one numerical symbol exists
|
17
|
+
INTEGER_STRICT = /^(?:[-+]?0b[_]*[0-1][0-1_]* (?# base 2)
|
18
|
+
|[-+]?0[_]*[0-7][0-7_]* (?# base 8)
|
19
|
+
|[-+]?(0|[1-9][0-9_]*) (?# base 10)
|
20
|
+
|[-+]?0x[_]*[0-9a-fA-F][0-9a-fA-F_]* (?# base 16))$/x
|
19
21
|
|
20
22
|
# Same as above, but allows commas.
|
21
23
|
# Not to YML spec, but kept for backwards compatibility
|
22
|
-
INTEGER_LEGACY = /^(?:[-+]?0b[0-1_,]
|
23
|
-
|[-+]?0[0-7_,]
|
24
|
+
INTEGER_LEGACY = /^(?:[-+]?0b[_,]*[0-1][0-1_,]* (?# base 2)
|
25
|
+
|[-+]?0[_,]*[0-7][0-7_,]* (?# base 8)
|
24
26
|
|[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
|
25
|
-
|[-+]?0x[0-9a-fA-F_,]
|
27
|
+
|[-+]?0x[_,]*[0-9a-fA-F][0-9a-fA-F_,]* (?# base 16))$/x
|
26
28
|
|
27
29
|
attr_reader :class_loader
|
28
30
|
|
@@ -61,7 +63,6 @@ module Psych
|
|
61
63
|
string
|
62
64
|
end
|
63
65
|
elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
|
64
|
-
require 'date'
|
65
66
|
begin
|
66
67
|
class_loader.date.strptime(string, '%F', Date::GREGORIAN)
|
67
68
|
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]
|
@@ -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
@@ -340,7 +340,7 @@ module Psych
|
|
340
340
|
# provided, the object contained in the first document will be returned.
|
341
341
|
# +filename+ will be used in the exception message if any exception
|
342
342
|
# is raised while parsing. If +yaml+ is empty, it returns
|
343
|
-
# the specified +fallback+ return value, which defaults to +
|
343
|
+
# the specified +fallback+ return value, which defaults to +nil+.
|
344
344
|
#
|
345
345
|
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
346
346
|
#
|
@@ -479,6 +479,7 @@ module Psych
|
|
479
479
|
#
|
480
480
|
# Default: <tt>2</tt>.
|
481
481
|
# [<tt>:line_width</tt>] Max character to wrap line at.
|
482
|
+
# For unlimited line width use <tt>-1</tt>.
|
482
483
|
#
|
483
484
|
# Default: <tt>0</tt> (meaning "wrap at 81").
|
484
485
|
# [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
|
@@ -489,6 +490,10 @@ module Psych
|
|
489
490
|
#
|
490
491
|
# Default: <tt>false</tt>.
|
491
492
|
#
|
493
|
+
# [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
|
494
|
+
#
|
495
|
+
# Default: <tt>false</tt>.
|
496
|
+
#
|
492
497
|
# Example:
|
493
498
|
#
|
494
499
|
# # Dump an array, get back a YAML string
|
@@ -502,6 +507,9 @@ module Psych
|
|
502
507
|
#
|
503
508
|
# # Dump an array to an IO with indentation set
|
504
509
|
# Psych.dump(['a', ['b']], StringIO.new, indentation: 3)
|
510
|
+
#
|
511
|
+
# # Dump hash with symbol keys as string
|
512
|
+
# Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
|
505
513
|
def self.dump o, io = nil, options = {}
|
506
514
|
if Hash === io
|
507
515
|
options = io
|
@@ -552,6 +560,7 @@ module Psych
|
|
552
560
|
#
|
553
561
|
# Default: <tt>2</tt>.
|
554
562
|
# [<tt>:line_width</tt>] Max character to wrap line at.
|
563
|
+
# For unlimited line width use <tt>-1</tt>.
|
555
564
|
#
|
556
565
|
# Default: <tt>0</tt> (meaning "wrap at 81").
|
557
566
|
# [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
|
@@ -562,6 +571,10 @@ module Psych
|
|
562
571
|
#
|
563
572
|
# Default: <tt>false</tt>.
|
564
573
|
#
|
574
|
+
# [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
|
575
|
+
#
|
576
|
+
# Default: <tt>false</tt>.
|
577
|
+
#
|
565
578
|
# Example:
|
566
579
|
#
|
567
580
|
# # Dump an array, get back a YAML string
|
@@ -575,6 +588,9 @@ module Psych
|
|
575
588
|
#
|
576
589
|
# # Dump an array to an IO with indentation set
|
577
590
|
# Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
|
591
|
+
#
|
592
|
+
# # Dump hash with symbol keys as string
|
593
|
+
# Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
|
578
594
|
def self.safe_dump o, io = nil, options = {}
|
579
595
|
if Hash === io
|
580
596
|
options = io
|
@@ -653,7 +669,7 @@ module Psych
|
|
653
669
|
###
|
654
670
|
# Safely loads the document contained in +filename+. Returns the yaml contained in
|
655
671
|
# +filename+ as a Ruby object, or if the file is empty, it returns
|
656
|
-
# the specified +fallback+ return value, which defaults to +
|
672
|
+
# the specified +fallback+ return value, which defaults to +nil+.
|
657
673
|
# See safe_load for options.
|
658
674
|
def self.safe_load_file filename, **kwargs
|
659
675
|
File.open(filename, 'r:bom|utf-8') { |f|
|
@@ -664,7 +680,7 @@ module Psych
|
|
664
680
|
###
|
665
681
|
# Loads the document contained in +filename+. Returns the yaml contained in
|
666
682
|
# +filename+ as a Ruby object, or if the file is empty, it returns
|
667
|
-
# the specified +fallback+ return value, which defaults to +
|
683
|
+
# the specified +fallback+ return value, which defaults to +nil+.
|
668
684
|
# See load for options.
|
669
685
|
def self.load_file filename, **kwargs
|
670
686
|
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.
|
4
|
+
version: 5.2.0.beta2
|
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-11-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: stringio
|
@@ -97,7 +97,8 @@ licenses:
|
|
97
97
|
- MIT
|
98
98
|
metadata:
|
99
99
|
msys2_mingw_dependencies: libyaml
|
100
|
-
|
100
|
+
changelog_uri: https://github.com/ruby/psych/releases
|
101
|
+
post_install_message:
|
101
102
|
rdoc_options:
|
102
103
|
- "--main"
|
103
104
|
- README.md
|
@@ -114,8 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
|
-
rubygems_version: 3.5.
|
118
|
-
signing_key:
|
118
|
+
rubygems_version: 3.5.11
|
119
|
+
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Psych is a YAML parser and emitter
|
121
122
|
test_files: []
|