psych 3.2.0-java → 4.0.0-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e956d1f39d537bbab914f9d69e070bc18268aa68ecf0ed219f515ae254409654
4
- data.tar.gz: c0a085a0afa83a1e78b8f4521a9904e4d800758ecdaff7efe9895faf060ad31c
3
+ metadata.gz: 5149acda4b0d41732db12bc694d4e72b0f5a511b628389ec0add96cef04d3b23
4
+ data.tar.gz: 4706cd6d83b23b106bdf5b5ef5953cdb416992bfa5ae774bb5f57e2f5394c1c8
5
5
  SHA512:
6
- metadata.gz: 07e866fdc5b8a36fd037ebc6fe1fffa585c4da0a53a997eb0e09fad12717a3bc91d8005fcd9648602b2008e8b648a028b7133291d1306c2c6998a0e15f4be170
7
- data.tar.gz: e31fe82bdef97efab8bb201a9fdb06eeafd94413890b2f890087ca15780738e137be16cac2680d2c40bed3a93e32836fa4819494c047e482c9784c8b22229db7
6
+ metadata.gz: 109458fa5a2da076004e322aa34f8b777be41d9dd3f51e27e4f6282e14896d84b8c9964f5a748803ba4873fbcf3857e72aa9993952997ea962c9104f9a4af969
7
+ data.tar.gz: cf2cb03494fade26c250914388b11ade2d529e81ddfa4bee119c9a5a149681239c6d9c81261f5ec247540a40a137a14e96fcaac4190b9db94ca0a92167410fe8
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'rake-compiler', ">= 0.4.1"
7
- gem 'minitest', "~> 5.0"
7
+ gem 'test-unit'
8
8
  gem 'ruby-maven', :platforms => :jruby
9
9
  end
data/README.md CHANGED
@@ -12,8 +12,8 @@ serialize and de-serialize most Ruby objects to and from the YAML format.
12
12
  ## Examples
13
13
 
14
14
  ```ruby
15
- # Load YAML in to a Ruby object
16
- Psych.load('--- foo') # => 'foo'
15
+ # Safely load YAML in to a Ruby object
16
+ Psych.safe_load('--- foo') # => 'foo'
17
17
 
18
18
  # Emit YAML from a Ruby object
19
19
  Psych.dump("foo") # => "--- foo\n...\n"
data/Rakefile CHANGED
@@ -3,8 +3,8 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  require "rake/testtask"
5
5
  Rake::TestTask.new(:test) do |t|
6
- t.libs << "test"
7
- t.libs << "lib"
6
+ t.libs << "test/lib" << "test"
7
+ t.ruby_opts << "-rhelper"
8
8
  t.test_files = FileList['test/**/test_*.rb']
9
9
  t.verbose = true
10
10
  t.warning = true
@@ -31,4 +31,11 @@ else
31
31
  Rake::ExtensionTask.new("psych")
32
32
  end
33
33
 
34
+ task :sync_tool do
35
+ require 'fileutils'
36
+ FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
37
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
38
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
39
+ end
40
+
34
41
  task :default => [:compile, :test]
data/ext/psych/psych.c CHANGED
@@ -22,6 +22,9 @@ VALUE mPsych;
22
22
 
23
23
  void Init_psych(void)
24
24
  {
25
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
26
+ RB_EXT_RACTOR_SAFE(true);
27
+ #endif
25
28
  mPsych = rb_define_module("Psych");
26
29
 
27
30
  rb_define_singleton_method(mPsych, "libyaml_version", libyaml_version, 0);
@@ -541,4 +541,4 @@ yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
541
541
  (void)POP(parser, *ctx);
542
542
 
543
543
  return 1;
544
- }
544
+ }
@@ -273,7 +273,7 @@
273
273
  * The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation
274
274
  * increase that precedes a block collection (cf. the INDENT token in Python).
275
275
  * The token BLOCK-END denote indentation decrease that ends a block collection
276
- * (cf. the DEDENT token in Python). However YAML has some syntax pecularities
276
+ * (cf. the DEDENT token in Python). However YAML has some syntax peculiarities
277
277
  * that makes detections of these tokens more complex.
278
278
  *
279
279
  * The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators
@@ -3287,7 +3287,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
3287
3287
 
3288
3288
  /* Check if we are at the end of the scalar. */
3289
3289
 
3290
- /* Fix for crash unitialized value crash
3290
+ /* Fix for crash uninitialized value crash
3291
3291
  * Credit for the bug and input is to OSS Fuzz
3292
3292
  * Credit for the fix to Alex Gaynor
3293
3293
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file yaml.h
3
3
  * @brief Public interface for libyaml.
4
- *
4
+ *
5
5
  * Include the header file with the code:
6
6
  * @code
7
7
  * #include <yaml.h>
@@ -390,7 +390,7 @@ typedef struct yaml_event_s {
390
390
 
391
391
  /** The event data. */
392
392
  union {
393
-
393
+
394
394
  /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
395
395
  struct {
396
396
  /** The document encoding. */
@@ -726,7 +726,7 @@ struct yaml_node_s {
726
726
 
727
727
  /** The node data. */
728
728
  union {
729
-
729
+
730
730
  /** The scalar parameters (for @c YAML_SCALAR_NODE). */
731
731
  struct {
732
732
  /** The scalar value. */
@@ -1095,7 +1095,7 @@ typedef struct yaml_parser_s {
1095
1095
  yaml_error_type_t error;
1096
1096
  /** Error description. */
1097
1097
  const char *problem;
1098
- /** The byte about which the problem occured. */
1098
+ /** The byte about which the problem occurred. */
1099
1099
  size_t problem_offset;
1100
1100
  /** The problematic value (@c -1 is none). */
1101
1101
  int problem_value;
@@ -1335,7 +1335,7 @@ yaml_parser_delete(yaml_parser_t *parser);
1335
1335
  * Set a string input.
1336
1336
  *
1337
1337
  * Note that the @a input pointer must be valid while the @a parser object
1338
- * exists. The application is responsible for destroing @a input after
1338
+ * exists. The application is responsible for destroying @a input after
1339
1339
  * destroying the @a parser.
1340
1340
  *
1341
1341
  * @param[in,out] parser A parser object.
@@ -1734,7 +1734,7 @@ typedef struct yaml_emitter_s {
1734
1734
  size_t length;
1735
1735
  /** Does the scalar contain line breaks? */
1736
1736
  int multiline;
1737
- /** Can the scalar be expessed in the flow plain style? */
1737
+ /** Can the scalar be expressed in the flow plain style? */
1738
1738
  int flow_plain_allowed;
1739
1739
  /** Can the scalar be expressed in the block plain style? */
1740
1740
  int block_plain_allowed;
@@ -1950,7 +1950,7 @@ yaml_emitter_close(yaml_emitter_t *emitter);
1950
1950
  /**
1951
1951
  * Emit a YAML document.
1952
1952
  *
1953
- * The documen object may be generated using the yaml_parser_load() function
1953
+ * The document object may be generated using the yaml_parser_load() function
1954
1954
  * or the yaml_document_initialize() function. The emitter takes the
1955
1955
  * responsibility for the document object and destroys its content after
1956
1956
  * it is emitted. The document object is destroyed even if the function fails.
@@ -2,7 +2,7 @@
2
2
  #include RUBY_EXTCONF_H
3
3
  #endif
4
4
 
5
- #if HAVE_CONFIG_H
5
+ #ifdef HAVE_CONFIG_H
6
6
  #include "config.h"
7
7
  #endif
8
8
 
data/lib/psych.rb CHANGED
@@ -74,12 +74,15 @@ require 'psych/class_loader'
74
74
  #
75
75
  # ==== Reading from a string
76
76
  #
77
- # Psych.load("--- a") # => 'a'
78
- # Psych.load("---\n - a\n - b") # => ['a', 'b']
77
+ # Psych.safe_load("--- a") # => 'a'
78
+ # Psych.safe_load("---\n - a\n - b") # => ['a', 'b']
79
+ # # From a trusted string:
80
+ # Psych.load("--- !ruby/range\nbegin: 0\nend: 42\nexcl: false\n") # => 0..42
79
81
  #
80
82
  # ==== Reading from a file
81
83
  #
82
- # Psych.load_file("database.yml")
84
+ # Psych.safe_load_file("data.yml", permitted_classes: [Date])
85
+ # Psych.load_file("trusted_database.yml")
83
86
  #
84
87
  # ==== Exception handling
85
88
  #
@@ -230,10 +233,7 @@ require 'psych/class_loader'
230
233
 
231
234
  module Psych
232
235
  # The version of libyaml Psych is using
233
- LIBYAML_VERSION = Psych.libyaml_version.join '.'
234
- # Deprecation guard
235
- NOT_GIVEN = Object.new
236
- private_constant :NOT_GIVEN
236
+ LIBYAML_VERSION = Psych.libyaml_version.join('.').freeze
237
237
 
238
238
  ###
239
239
  # Load +yaml+ in to a Ruby data structure. If multiple documents are
@@ -246,11 +246,11 @@ module Psych
246
246
  #
247
247
  # Example:
248
248
  #
249
- # Psych.load("--- a") # => 'a'
250
- # Psych.load("---\n - a\n - b") # => ['a', 'b']
249
+ # Psych.unsafe_load("--- a") # => 'a'
250
+ # Psych.unsafe_load("---\n - a\n - b") # => ['a', 'b']
251
251
  #
252
252
  # begin
253
- # Psych.load("--- `", filename: "file.txt")
253
+ # Psych.unsafe_load("--- `", filename: "file.txt")
254
254
  # rescue Psych::SyntaxError => ex
255
255
  # ex.file # => 'file.txt'
256
256
  # ex.message # => "(file.txt): found character that cannot start any token"
@@ -259,26 +259,21 @@ module Psych
259
259
  # When the optional +symbolize_names+ keyword argument is set to a
260
260
  # true value, returns symbols for keys in Hash objects (default: strings).
261
261
  #
262
- # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
263
- # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
262
+ # Psych.unsafe_load("---\n foo: bar") # => {"foo"=>"bar"}
263
+ # Psych.unsafe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
264
264
  #
265
265
  # Raises a TypeError when `yaml` parameter is NilClass
266
266
  #
267
267
  # NOTE: This method *should not* be used to parse untrusted documents, such as
268
268
  # YAML documents that are supplied via user input. Instead, please use the
269
- # safe_load method.
269
+ # load method or the safe_load method.
270
270
  #
271
- def self.load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false, freeze: false
272
- if legacy_filename != NOT_GIVEN
273
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
274
- filename = legacy_filename
275
- end
276
-
271
+ def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false
277
272
  result = parse(yaml, filename: filename)
278
273
  return fallback unless result
279
- result = result.to_ruby(symbolize_names: symbolize_names, freeze: freeze) if result
280
- result
274
+ result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
281
275
  end
276
+ class << self; alias :load :unsafe_load; end
282
277
 
283
278
  ###
284
279
  # Safely load the yaml string in +yaml+. By default, only the following
@@ -324,27 +319,7 @@ module Psych
324
319
  # Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"}
325
320
  # Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
326
321
  #
327
- def self.safe_load yaml, legacy_permitted_classes = NOT_GIVEN, legacy_permitted_symbols = NOT_GIVEN, legacy_aliases = NOT_GIVEN, legacy_filename = NOT_GIVEN, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
328
- if legacy_permitted_classes != NOT_GIVEN
329
- warn_with_uplevel 'Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.', uplevel: 1 if $VERBOSE
330
- permitted_classes = legacy_permitted_classes
331
- end
332
-
333
- if legacy_permitted_symbols != NOT_GIVEN
334
- warn_with_uplevel 'Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead.', uplevel: 1 if $VERBOSE
335
- permitted_symbols = legacy_permitted_symbols
336
- end
337
-
338
- if legacy_aliases != NOT_GIVEN
339
- warn_with_uplevel 'Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead.', uplevel: 1 if $VERBOSE
340
- aliases = legacy_aliases
341
- end
342
-
343
- if legacy_filename != NOT_GIVEN
344
- warn_with_uplevel 'Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
345
- filename = legacy_filename
346
- end
347
-
322
+ def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
348
323
  result = parse(yaml, filename: filename)
349
324
  return fallback unless result
350
325
 
@@ -360,6 +335,46 @@ module Psych
360
335
  result
361
336
  end
362
337
 
338
+ ###
339
+ # Load +yaml+ in to a Ruby data structure. If multiple documents are
340
+ # provided, the object contained in the first document will be returned.
341
+ # +filename+ will be used in the exception message if any exception
342
+ # is raised while parsing. If +yaml+ is empty, it returns
343
+ # the specified +fallback+ return value, which defaults to +false+.
344
+ #
345
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
346
+ #
347
+ # Example:
348
+ #
349
+ # Psych.load("--- a") # => 'a'
350
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
351
+ #
352
+ # begin
353
+ # Psych.load("--- `", filename: "file.txt")
354
+ # rescue Psych::SyntaxError => ex
355
+ # ex.file # => 'file.txt'
356
+ # ex.message # => "(file.txt): found character that cannot start any token"
357
+ # end
358
+ #
359
+ # When the optional +symbolize_names+ keyword argument is set to a
360
+ # true value, returns symbols for keys in Hash objects (default: strings).
361
+ #
362
+ # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
363
+ # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
364
+ #
365
+ # Raises a TypeError when `yaml` parameter is NilClass. This method is
366
+ # similar to `safe_load` except that `Symbol` objects are allowed by default.
367
+ #
368
+ def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
369
+ safe_load yaml, permitted_classes: permitted_classes,
370
+ permitted_symbols: permitted_symbols,
371
+ aliases: aliases,
372
+ filename: filename,
373
+ fallback: fallback,
374
+ symbolize_names: symbolize_names,
375
+ freeze: freeze
376
+ end
377
+
363
378
  ###
364
379
  # Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
365
380
  # +filename+ is used in the exception message if a Psych::SyntaxError is
@@ -379,22 +394,12 @@ module Psych
379
394
  # end
380
395
  #
381
396
  # See Psych::Nodes for more information about YAML AST.
382
- def self.parse yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: NOT_GIVEN
383
- if legacy_filename != NOT_GIVEN
384
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse is deprecated. Use keyword argument like Psych.parse(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
385
- filename = legacy_filename
386
- end
387
-
397
+ def self.parse yaml, filename: nil
388
398
  parse_stream(yaml, filename: filename) do |node|
389
399
  return node
390
400
  end
391
401
 
392
- if fallback != NOT_GIVEN
393
- warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE
394
- fallback
395
- else
396
- false
397
- end
402
+ false
398
403
  end
399
404
 
400
405
  ###
@@ -443,12 +448,7 @@ module Psych
443
448
  # Raises a TypeError when NilClass is passed.
444
449
  #
445
450
  # See Psych::Nodes for more information about YAML AST.
446
- def self.parse_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, &block
447
- if legacy_filename != NOT_GIVEN
448
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse_stream is deprecated. Use keyword argument like Psych.parse_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
449
- filename = legacy_filename
450
- end
451
-
451
+ def self.parse_stream yaml, filename: nil, &block
452
452
  if block_given?
453
453
  parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
454
454
  parser.parse yaml, filename
@@ -549,18 +549,13 @@ module Psych
549
549
  # end
550
550
  # list # => ['foo', 'bar']
551
551
  #
552
- def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: []
553
- if legacy_filename != NOT_GIVEN
554
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load_stream is deprecated. Use keyword argument like Psych.load_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
555
- filename = legacy_filename
556
- end
557
-
552
+ def self.load_stream yaml, filename: nil, fallback: [], **kwargs
558
553
  result = if block_given?
559
554
  parse_stream(yaml, filename: filename) do |node|
560
- yield node.to_ruby
555
+ yield node.to_ruby(**kwargs)
561
556
  end
562
557
  else
563
- parse_stream(yaml, filename: filename).children.map(&:to_ruby)
558
+ parse_stream(yaml, filename: filename).children.map { |node| node.to_ruby(**kwargs) }
564
559
  end
565
560
 
566
561
  return fallback if result.is_a?(Array) && result.empty?
@@ -571,35 +566,49 @@ module Psych
571
566
  # Load the document contained in +filename+. Returns the yaml contained in
572
567
  # +filename+ as a Ruby object, or if the file is empty, it returns
573
568
  # the specified +fallback+ return value, which defaults to +false+.
574
- def self.load_file filename, fallback: false
569
+ #
570
+ # NOTE: This method *should not* be used to parse untrusted documents, such as
571
+ # YAML documents that are supplied via user input. Instead, please use the
572
+ # safe_load_file method.
573
+ def self.unsafe_load_file filename, **kwargs
574
+ File.open(filename, 'r:bom|utf-8') { |f|
575
+ self.unsafe_load f, filename: filename, **kwargs
576
+ }
577
+ end
578
+ class << self; alias :load_file :unsafe_load_file; end
579
+
580
+ ###
581
+ # Safely loads the document contained in +filename+. Returns the yaml contained in
582
+ # +filename+ as a Ruby object, or if the file is empty, it returns
583
+ # the specified +fallback+ return value, which defaults to +false+.
584
+ # See safe_load for options.
585
+ def self.safe_load_file filename, **kwargs
575
586
  File.open(filename, 'r:bom|utf-8') { |f|
576
- self.load f, filename: filename, fallback: fallback
587
+ self.safe_load f, filename: filename, **kwargs
577
588
  }
578
589
  end
590
+ class << self; alias load_file safe_load_file end
579
591
 
580
592
  # :stopdoc:
581
- @domain_types = {}
582
593
  def self.add_domain_type domain, type_tag, &block
583
594
  key = ['tag', domain, type_tag].join ':'
584
- @domain_types[key] = [key, block]
585
- @domain_types["tag:#{type_tag}"] = [key, block]
595
+ domain_types[key] = [key, block]
596
+ domain_types["tag:#{type_tag}"] = [key, block]
586
597
  end
587
598
 
588
599
  def self.add_builtin_type type_tag, &block
589
600
  domain = 'yaml.org,2002'
590
601
  key = ['tag', domain, type_tag].join ':'
591
- @domain_types[key] = [key, block]
602
+ domain_types[key] = [key, block]
592
603
  end
593
604
 
594
605
  def self.remove_type type_tag
595
- @domain_types.delete type_tag
606
+ domain_types.delete type_tag
596
607
  end
597
608
 
598
- @load_tags = {}
599
- @dump_tags = {}
600
609
  def self.add_tag tag, klass
601
- @load_tags[tag] = klass.name
602
- @dump_tags[klass] = tag
610
+ load_tags[tag] = klass.name
611
+ dump_tags[klass] = tag
603
612
  end
604
613
 
605
614
  # Workaround for emulating `warn '...', uplevel: 1` in Ruby 2.4 or lower.
@@ -618,9 +627,32 @@ module Psych
618
627
  private_class_method :warn_with_uplevel, :parse_caller
619
628
 
620
629
  class << self
621
- attr_accessor :load_tags
622
- attr_accessor :dump_tags
623
- attr_accessor :domain_types
630
+ if defined?(Ractor)
631
+ require 'forwardable'
632
+ extend Forwardable
633
+
634
+ class Config
635
+ attr_accessor :load_tags, :dump_tags, :domain_types
636
+ def initialize
637
+ @load_tags = {}
638
+ @dump_tags = {}
639
+ @domain_types = {}
640
+ end
641
+ end
642
+
643
+ def config
644
+ Ractor.current[:PsychConfig] ||= Config.new
645
+ end
646
+
647
+ def_delegators :config, :load_tags, :dump_tags, :domain_types, :load_tags=, :dump_tags=, :domain_types=
648
+ else
649
+ attr_accessor :load_tags
650
+ attr_accessor :dump_tags
651
+ attr_accessor :domain_types
652
+ end
624
653
  end
654
+ self.load_tags = {}
655
+ self.dump_tags = {}
656
+ self.domain_types = {}
625
657
  # :startdoc:
626
658
  end
@@ -35,9 +35,11 @@ module Psych
35
35
 
36
36
  constants.each do |const|
37
37
  konst = const_get const
38
- define_method(const.to_s.downcase) do
39
- load konst
40
- end
38
+ class_eval <<~RUBY
39
+ def #{const.to_s.downcase}
40
+ load #{konst.inspect}
41
+ end
42
+ RUBY
41
43
  end
42
44
 
43
45
  private
@@ -69,7 +71,7 @@ module Psych
69
71
  rescue
70
72
  nil
71
73
  end
72
- }.compact]
74
+ }.compact].freeze
73
75
 
74
76
  class Restricted < ClassLoader
75
77
  def initialize classes, symbols
data/lib/psych/handler.rb CHANGED
@@ -119,7 +119,7 @@ module Psych
119
119
  # +tag+ is an associated tag or nil
120
120
  # +plain+ is a boolean value
121
121
  # +quoted+ is a boolean value
122
- # +style+ is an integer idicating the string style
122
+ # +style+ is an integer indicating the string style
123
123
  #
124
124
  # See the constants in Psych::Nodes::Scalar for the possible values of
125
125
  # +style+
@@ -50,7 +50,7 @@ module Psych
50
50
  # +tag+ is an associated tag or nil
51
51
  # +plain+ is a boolean value
52
52
  # +quoted+ is a boolean value
53
- # +style+ is an integer idicating the string style
53
+ # +style+ is an integer indicating the string style
54
54
  #
55
55
  # == See Also
56
56
  #
@@ -1,10 +1,10 @@
1
-
2
1
  # frozen_string_literal: true
2
+
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '3.2.0'
5
+ VERSION = '4.0.0'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
- DEFAULT_SNAKEYAML_VERSION = '1.26'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze
9
9
  end
10
10
  end
@@ -24,6 +24,7 @@ module Psych
24
24
  super()
25
25
  @st = {}
26
26
  @ss = ss
27
+ @load_tags = Psych.load_tags
27
28
  @domain_types = Psych.domain_types
28
29
  @class_loader = class_loader
29
30
  @symbolize_names = symbolize_names
@@ -48,7 +49,7 @@ module Psych
48
49
  end
49
50
 
50
51
  def deserialize o
51
- if klass = resolve_class(Psych.load_tags[o.tag])
52
+ if klass = resolve_class(@load_tags[o.tag])
52
53
  instance = klass.allocate
53
54
 
54
55
  if instance.respond_to?(:init_with)
@@ -128,7 +129,7 @@ module Psych
128
129
  end
129
130
 
130
131
  def visit_Psych_Nodes_Sequence o
131
- if klass = resolve_class(Psych.load_tags[o.tag])
132
+ if klass = resolve_class(@load_tags[o.tag])
132
133
  instance = klass.allocate
133
134
 
134
135
  if instance.respond_to?(:init_with)
@@ -160,8 +161,8 @@ module Psych
160
161
  end
161
162
 
162
163
  def visit_Psych_Nodes_Mapping o
163
- if Psych.load_tags[o.tag]
164
- return revive(resolve_class(Psych.load_tags[o.tag]), o)
164
+ if @load_tags[o.tag]
165
+ return revive(resolve_class(@load_tags[o.tag]), o)
165
166
  end
166
167
  return revive_hash(register(o, {}), o) unless o.tag
167
168
 
@@ -326,6 +327,7 @@ module Psych
326
327
  end
327
328
 
328
329
  private
330
+
329
331
  def register node, object
330
332
  @st[node.anchor] = object if node.anchor
331
333
  object
@@ -337,7 +339,7 @@ module Psych
337
339
  list
338
340
  end
339
341
 
340
- def revive_hash hash, o
342
+ def revive_hash hash, o, tagged= false
341
343
  o.children.each_slice(2) { |k,v|
342
344
  key = accept(k)
343
345
  val = accept(v)
@@ -364,7 +366,7 @@ module Psych
364
366
  hash[key] = val
365
367
  end
366
368
  else
367
- if @symbolize_names
369
+ if !tagged && @symbolize_names && key.is_a?(String)
368
370
  key = key.to_sym
369
371
  elsif !@freeze
370
372
  key = deduplicate(key)
@@ -402,7 +404,7 @@ module Psych
402
404
 
403
405
  def revive klass, node
404
406
  s = register(node, klass.allocate)
405
- init_with(s, revive_hash({}, node), node)
407
+ init_with(s, revive_hash({}, node, true), node)
406
408
  end
407
409
 
408
410
  def init_with o, h, node
@@ -8,12 +8,26 @@ module Psych
8
8
 
9
9
  private
10
10
 
11
- DISPATCH = Hash.new do |hash, klass|
12
- hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
11
+ # @api private
12
+ def self.dispatch_cache
13
+ Hash.new do |hash, klass|
14
+ hash[klass] = :"visit_#{klass.name.gsub('::', '_')}"
15
+ end.compare_by_identity
16
+ end
17
+
18
+ if defined?(Ractor)
19
+ def dispatch
20
+ @dispatch_cache ||= (Ractor.current[:Psych_Visitors_Visitor] ||= Visitor.dispatch_cache)
21
+ end
22
+ else
23
+ DISPATCH = dispatch_cache
24
+ def dispatch
25
+ DISPATCH
26
+ end
13
27
  end
14
28
 
15
29
  def visit target
16
- send DISPATCH[target.class], target
30
+ send dispatch[target.class], target
17
31
  end
18
32
  end
19
33
  end
@@ -80,7 +80,7 @@ module Psych
80
80
  raise(TypeError, "Can't dump #{target.class}") unless method
81
81
 
82
82
  h[klass] = method
83
- end
83
+ end.compare_by_identity
84
84
  end
85
85
 
86
86
  def start encoding = Nodes::Stream::UTF8
@@ -509,9 +509,9 @@ module Psych
509
509
  def emit_coder c, o
510
510
  case c.type
511
511
  when :scalar
512
- @emitter.scalar c.scalar, nil, c.tag, c.tag.nil?, false, Nodes::Scalar::ANY
512
+ @emitter.scalar c.scalar, nil, c.tag, c.tag.nil?, false, c.style
513
513
  when :seq
514
- @emitter.start_sequence nil, c.tag, c.tag.nil?, Nodes::Sequence::BLOCK
514
+ @emitter.start_sequence nil, c.tag, c.tag.nil?, c.style
515
515
  c.seq.each do |thing|
516
516
  accept thing
517
517
  end
data/psych.gemspec CHANGED
@@ -46,7 +46,6 @@ DESCRIPTION
46
46
  s.extra_rdoc_files = ["README.md"]
47
47
 
48
48
  s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
49
- s.rubygems_version = "2.5.1"
50
49
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
51
50
 
52
51
  if RUBY_ENGINE == 'jruby'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 4.0.0
5
5
  platform: java
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-17 00:00:00.000000000 Z
13
+ date: 2021-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements:
140
- - jar org.yaml:snakeyaml, 1.26
140
+ - jar org.yaml:snakeyaml, 1.28
141
141
  rubygems_version: 3.0.6
142
142
  signing_key:
143
143
  specification_version: 4