psych 3.3.2 → 5.2.2

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +24 -0
  3. data/README.md +6 -5
  4. data/ext/psych/depend +13 -1
  5. data/ext/psych/extconf.rb +40 -30
  6. data/ext/psych/psych.c +1 -1
  7. data/ext/psych/psych_emitter.c +155 -120
  8. data/ext/psych/psych_parser.c +267 -281
  9. data/lib/psych/class_loader.rb +5 -5
  10. data/lib/psych/core_ext.rb +1 -1
  11. data/lib/psych/exception.rb +16 -2
  12. data/lib/psych/handlers/document_stream.rb +1 -1
  13. data/lib/psych/handlers/recorder.rb +1 -1
  14. data/lib/psych/json/stream.rb +2 -2
  15. data/lib/psych/json/tree_builder.rb +1 -1
  16. data/lib/psych/nodes/node.rb +5 -5
  17. data/lib/psych/nodes.rb +7 -7
  18. data/lib/psych/parser.rb +13 -0
  19. data/lib/psych/scalar_scanner.rb +24 -19
  20. data/lib/psych/syntax_error.rb +1 -1
  21. data/lib/psych/tree_builder.rb +3 -3
  22. data/lib/psych/versions.rb +2 -2
  23. data/lib/psych/visitors/json_tree.rb +1 -1
  24. data/lib/psych/visitors/to_ruby.rb +12 -11
  25. data/lib/psych/visitors/yaml_tree.rb +71 -27
  26. data/lib/psych/visitors.rb +6 -6
  27. data/lib/psych.rb +204 -106
  28. metadata +37 -25
  29. data/.gitignore +0 -16
  30. data/Gemfile +0 -9
  31. data/Mavenfile +0 -7
  32. data/Rakefile +0 -41
  33. data/bin/console +0 -7
  34. data/bin/setup +0 -6
  35. data/ext/psych/yaml/LICENSE +0 -19
  36. data/ext/psych/yaml/api.c +0 -1393
  37. data/ext/psych/yaml/config.h +0 -80
  38. data/ext/psych/yaml/dumper.c +0 -394
  39. data/ext/psych/yaml/emitter.c +0 -2358
  40. data/ext/psych/yaml/loader.c +0 -544
  41. data/ext/psych/yaml/parser.c +0 -1375
  42. data/ext/psych/yaml/reader.c +0 -469
  43. data/ext/psych/yaml/scanner.c +0 -3598
  44. data/ext/psych/yaml/writer.c +0 -141
  45. data/ext/psych/yaml/yaml.h +0 -1985
  46. data/ext/psych/yaml/yaml_private.h +0 -688
  47. data/psych.gemspec +0 -67
@@ -15,5 +15,5 @@ class Object
15
15
  end
16
16
 
17
17
  if defined?(::IRB)
18
- require 'psych/y'
18
+ require_relative 'y'
19
19
  end
@@ -6,9 +6,23 @@ module Psych
6
6
  class BadAlias < Exception
7
7
  end
8
8
 
9
+ # Subclasses `BadAlias` for backwards compatibility
10
+ class AliasesNotEnabled < BadAlias
11
+ def initialize
12
+ super "Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`."
13
+ end
14
+ end
15
+
16
+ # Subclasses `BadAlias` for backwards compatibility
17
+ class AnchorNotDefined < BadAlias
18
+ def initialize anchor_name
19
+ super "An alias referenced an unknown anchor: #{anchor_name}"
20
+ end
21
+ end
22
+
9
23
  class DisallowedClass < Exception
10
- def initialize klass_name
11
- super "Tried to load unspecified class: #{klass_name}"
24
+ def initialize action, klass_name
25
+ super "Tried to #{action} unspecified class: #{klass_name}"
12
26
  end
13
27
  end
14
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/tree_builder'
2
+ require_relative '../tree_builder'
3
3
 
4
4
  module Psych
5
5
  module Handlers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/handler'
2
+ require_relative '../handler'
3
3
 
4
4
  module Psych
5
5
  module Handlers
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/json/ruby_events'
3
- require 'psych/json/yaml_events'
2
+ require_relative 'ruby_events'
3
+ require_relative 'yaml_events'
4
4
 
5
5
  module Psych
6
6
  module JSON
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/json/yaml_events'
2
+ require_relative 'yaml_events'
3
3
 
4
4
  module Psych
5
5
  module JSON
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'stringio'
3
- require 'psych/class_loader'
4
- require 'psych/scalar_scanner'
2
+ require_relative '../class_loader'
3
+ require_relative '../scalar_scanner'
5
4
 
6
5
  module Psych
7
6
  module Nodes
@@ -46,8 +45,8 @@ module Psych
46
45
  # Convert this node to Ruby.
47
46
  #
48
47
  # See also Psych::Visitors::ToRuby
49
- def to_ruby(symbolize_names: false, freeze: false)
50
- Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self)
48
+ def to_ruby(symbolize_names: false, freeze: false, strict_integer: false)
49
+ Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self)
51
50
  end
52
51
  alias :transform :to_ruby
53
52
 
@@ -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/nodes.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/nodes/node'
3
- require 'psych/nodes/stream'
4
- require 'psych/nodes/document'
5
- require 'psych/nodes/sequence'
6
- require 'psych/nodes/scalar'
7
- require 'psych/nodes/mapping'
8
- require 'psych/nodes/alias'
2
+ require_relative 'nodes/node'
3
+ require_relative 'nodes/stream'
4
+ require_relative 'nodes/document'
5
+ require_relative 'nodes/sequence'
6
+ require_relative 'nodes/scalar'
7
+ require_relative 'nodes/mapping'
8
+ require_relative 'nodes/alias'
9
9
 
10
10
  module Psych
11
11
  ###
data/lib/psych/parser.rb CHANGED
@@ -48,5 +48,18 @@ module Psych
48
48
  @handler = handler
49
49
  @external_encoding = ANY
50
50
  end
51
+
52
+ ###
53
+ # call-seq:
54
+ # parser.parse(yaml)
55
+ #
56
+ # Parse the YAML document contained in +yaml+. Events will be called on
57
+ # the handler set on the parser instance.
58
+ #
59
+ # See Psych::Parser and Psych::Parser#handler
60
+
61
+ def parse yaml, path = yaml.respond_to?(:path) ? yaml.path : "<unknown>"
62
+ _native_parse @handler, yaml, path
63
+ end
51
64
  end
52
65
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'strscan'
3
2
 
4
3
  module Psych
5
4
  ###
@@ -9,32 +8,39 @@ module Psych
9
8
  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)?))?$/
10
9
 
11
10
  # Taken from http://yaml.org/type/float.html
12
- FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
13
- |[-+]?\.(inf|Inf|INF)(?# infinity)
14
- |\.(nan|NaN|NAN)(?# not a number))$/x
15
-
16
- # Taken from http://yaml.org/type/int.html
17
- INTEGER = /^(?:[-+]?0b[0-1_,]+ (?# base 2)
18
- |[-+]?0[0-7_,]+ (?# base 8)
19
- |[-+]?(?:0|[1-9][0-9_,]*) (?# base 10)
20
- |[-+]?0x[0-9a-fA-F_,]+ (?# base 16))$/x
11
+ # Base 60, [-+]inf and NaN are handled separately
12
+ FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
13
+
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
+
20
+ # Same as above, but allows commas.
21
+ # Not to YML spec, but kept for backwards compatibility
22
+ INTEGER_LEGACY = /^(?:[-+]?0b[_,]*[0-1][0-1_,]* (?# base 2)
23
+ |[-+]?0[_,]*[0-7][0-7_,]* (?# base 8)
24
+ |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
25
+ |[-+]?0x[_,]*[0-9a-fA-F][0-9a-fA-F_,]* (?# base 16))$/x
21
26
 
22
27
  attr_reader :class_loader
23
28
 
24
29
  # Create a new scanner
25
- def initialize class_loader
30
+ def initialize class_loader, strict_integer: false
26
31
  @symbol_cache = {}
27
32
  @class_loader = class_loader
33
+ @strict_integer = strict_integer
28
34
  end
29
35
 
30
36
  # Tokenize +string+ returning the Ruby object
31
37
  def tokenize string
32
38
  return nil if string.empty?
33
39
  return @symbol_cache[string] if @symbol_cache.key?(string)
34
-
40
+ integer_regex = @strict_integer ? INTEGER_STRICT : INTEGER_LEGACY
35
41
  # Check for a String type, being careful not to get caught by hash keys, hex values, and
36
42
  # special floats (e.g., -.inf).
37
- if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
43
+ if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
38
44
  return string if string.length > 5
39
45
 
40
46
  if string.match?(/^[^ytonf~]/i)
@@ -55,13 +61,12 @@ module Psych
55
61
  string
56
62
  end
57
63
  elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
58
- require 'date'
59
64
  begin
60
- class_loader.date.strptime(string, '%Y-%m-%d')
65
+ class_loader.date.strptime(string, '%F', Date::GREGORIAN)
61
66
  rescue ArgumentError
62
67
  string
63
68
  end
64
- elsif string.match?(/^\.inf$/i)
69
+ elsif string.match?(/^\+?\.inf$/i)
65
70
  Float::INFINITY
66
71
  elsif string.match?(/^-\.inf$/i)
67
72
  -Float::INFINITY
@@ -89,9 +94,9 @@ module Psych
89
94
  if string.match?(/\A[-+]?\.\Z/)
90
95
  string
91
96
  else
92
- Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
97
+ Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
93
98
  end
94
- elsif string.match?(INTEGER)
99
+ elsif string.match?(integer_regex)
95
100
  parse_int string
96
101
  else
97
102
  string
@@ -101,7 +106,7 @@ module Psych
101
106
  ###
102
107
  # Parse and return an int from +string+
103
108
  def parse_int string
104
- Integer(string.gsub(/[,_]/, ''))
109
+ Integer(string.delete(',_'))
105
110
  end
106
111
 
107
112
  ###
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/exception'
2
+ require_relative 'exception'
3
3
 
4
4
  module Psych
5
5
  class SyntaxError < Psych::Exception
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/handler'
2
+ require_relative 'handler'
3
3
 
4
4
  module Psych
5
5
  ###
@@ -41,7 +41,7 @@ module Psych
41
41
  Sequence
42
42
  Mapping
43
43
  }.each do |node|
44
- class_eval %{
44
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
45
45
  def start_#{node.downcase}(anchor, tag, implicit, style)
46
46
  n = Nodes::#{node}.new(anchor, tag, implicit, style)
47
47
  set_start_location(n)
@@ -54,7 +54,7 @@ module Psych
54
54
  set_end_location(n)
55
55
  n
56
56
  end
57
- }
57
+ RUBY
58
58
  end
59
59
 
60
60
  ###
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '3.3.2'
5
+ VERSION = '5.2.2'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
- DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '2.7'.freeze
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/json/ruby_events'
2
+ require_relative '../json/ruby_events'
3
3
 
4
4
  module Psych
5
5
  module Visitors
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/scalar_scanner'
3
- require 'psych/class_loader'
4
- require 'psych/exception'
2
+ require_relative '../scalar_scanner'
3
+ require_relative '../class_loader'
4
+ require_relative '../exception'
5
5
 
6
6
  unless defined?(Regexp::NOENCODING)
7
7
  Regexp::NOENCODING = 32
@@ -12,9 +12,9 @@ module Psych
12
12
  ###
13
13
  # This class walks a YAML AST, converting each node to Ruby
14
14
  class ToRuby < Psych::Visitors::Visitor
15
- def self.create(symbolize_names: false, freeze: false)
15
+ def self.create(symbolize_names: false, freeze: false, strict_integer: false)
16
16
  class_loader = ClassLoader.new
17
- scanner = ScalarScanner.new class_loader
17
+ scanner = ScalarScanner.new class_loader, strict_integer: strict_integer
18
18
  new(scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze)
19
19
  end
20
20
 
@@ -36,7 +36,7 @@ module Psych
36
36
 
37
37
  unless @domain_types.empty? || !target.tag
38
38
  key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
39
- key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
39
+ key = "tag:#{key}" unless key.match?(/^(?:tag:|x-private)/)
40
40
 
41
41
  if @domain_types.key? key
42
42
  value, block = @domain_types[key]
@@ -79,8 +79,9 @@ 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
- @ss.parse_time(o.value).to_datetime
82
+ t = @ss.parse_time(o.value)
83
+ DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
84
+ (t.subsec/86400)
84
85
  when '!ruby/encoding'
85
86
  ::Encoding.find o.value
86
87
  when "!ruby/object:Complex"
@@ -99,7 +100,7 @@ module Psych
99
100
  source = $1
100
101
  options = 0
101
102
  lang = nil
102
- ($2 || '').split('').each do |option|
103
+ $2&.each_char do |option|
103
104
  case option
104
105
  when 'x' then options |= Regexp::EXTENDED
105
106
  when 'i' then options |= Regexp::IGNORECASE
@@ -323,7 +324,7 @@ module Psych
323
324
  end
324
325
 
325
326
  def visit_Psych_Nodes_Alias o
326
- @st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
327
+ @st.fetch(o.anchor) { raise AnchorNotDefined, o.anchor }
327
328
  end
328
329
 
329
330
  private
@@ -427,7 +428,7 @@ module Psych
427
428
 
428
429
  class NoAliasRuby < ToRuby
429
430
  def visit_Psych_Nodes_Alias o
430
- raise BadAlias, "Unknown alias: #{o.anchor}"
431
+ raise AliasesNotEnabled
431
432
  end
432
433
  end
433
434
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/tree_builder'
3
- require 'psych/scalar_scanner'
4
- require 'psych/class_loader'
2
+ require_relative '../tree_builder'
3
+ require_relative '../scalar_scanner'
4
+ require_relative '../class_loader'
5
5
 
6
6
  module Psych
7
7
  module Visitors
@@ -15,30 +15,25 @@ module Psych
15
15
  class YAMLTree < Psych::Visitors::Visitor
16
16
  class Registrar # :nodoc:
17
17
  def initialize
18
- @obj_to_id = {}
19
- @obj_to_node = {}
20
- @targets = []
18
+ @obj_to_id = {}.compare_by_identity
19
+ @obj_to_node = {}.compare_by_identity
21
20
  @counter = 0
22
21
  end
23
22
 
24
23
  def register target, node
25
- return unless target.respond_to? :object_id
26
- @targets << target
27
- @obj_to_node[target.object_id] = node
24
+ @obj_to_node[target] = node
28
25
  end
29
26
 
30
27
  def key? target
31
- @obj_to_node.key? target.object_id
32
- rescue NoMethodError
33
- false
28
+ @obj_to_node.key? target
34
29
  end
35
30
 
36
31
  def id_for target
37
- @obj_to_id[target.object_id] ||= (@counter += 1)
32
+ @obj_to_id[target] ||= (@counter += 1)
38
33
  end
39
34
 
40
35
  def node_for target
41
- @obj_to_node[target.object_id]
36
+ @obj_to_node[target]
42
37
  end
43
38
  end
44
39
 
@@ -70,6 +65,7 @@ module Psych
70
65
  fail(ArgumentError, "Invalid line_width #{@line_width}, must be non-negative or -1 for unlimited.")
71
66
  end
72
67
  end
68
+ @stringify_names = options[:stringify_names]
73
69
  @coders = []
74
70
 
75
71
  @dispatch_cache = Hash.new do |h,klass|
@@ -192,12 +188,13 @@ module Psych
192
188
  register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
193
189
  end
194
190
 
191
+ def visit_Date o
192
+ register o, visit_Integer(o.gregorian)
193
+ end
194
+
195
195
  def visit_DateTime o
196
- formatted = if o.offset.zero?
197
- o.strftime("%Y-%m-%d %H:%M:%S.%9N Z".freeze)
198
- else
199
- o.strftime("%Y-%m-%d %H:%M:%S.%9N %:z".freeze)
200
- end
196
+ t = o.italy
197
+ formatted = format_time t, t.offset.zero?
201
198
  tag = '!ruby/object:DateTime'
202
199
  register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY)
203
200
  end
@@ -235,7 +232,6 @@ module Psych
235
232
  end
236
233
  alias :visit_TrueClass :visit_Integer
237
234
  alias :visit_FalseClass :visit_Integer
238
- alias :visit_Date :visit_Integer
239
235
 
240
236
  def visit_Float o
241
237
  if o.nan?
@@ -265,18 +261,20 @@ module Psych
265
261
  style = Nodes::Scalar::LITERAL
266
262
  plain = false
267
263
  quote = false
268
- elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
264
+ elsif o.match?(/\n(?!\Z)/) # match \n except blank line at the end of string
269
265
  style = Nodes::Scalar::LITERAL
270
266
  elsif o == '<<'
271
267
  style = Nodes::Scalar::SINGLE_QUOTED
272
268
  tag = 'tag:yaml.org,2002:str'
273
269
  plain = false
274
270
  quote = false
271
+ elsif o == 'y' || o == 'Y' || o == 'n' || o == 'N'
272
+ style = Nodes::Scalar::DOUBLE_QUOTED
275
273
  elsif @line_width && o.length > @line_width
276
274
  style = Nodes::Scalar::FOLDED
277
- elsif o =~ /^[^[:word:]][^"]*$/
275
+ elsif o.match?(/^[^[:word:]][^"]*$/)
278
276
  style = Nodes::Scalar::DOUBLE_QUOTED
279
- elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
277
+ elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/.match?(o)
280
278
  style = Nodes::Scalar::SINGLE_QUOTED
281
279
  end
282
280
 
@@ -326,7 +324,7 @@ module Psych
326
324
  if o.class == ::Hash
327
325
  register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
328
326
  o.each do |k,v|
329
- accept k
327
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
330
328
  accept v
331
329
  end
332
330
  @emitter.end_mapping
@@ -339,7 +337,7 @@ module Psych
339
337
  register(o, @emitter.start_mapping(nil, '!set', false, Psych::Nodes::Mapping::BLOCK))
340
338
 
341
339
  o.each do |k,v|
342
- accept k
340
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
343
341
  accept v
344
342
  end
345
343
 
@@ -480,8 +478,8 @@ module Psych
480
478
  @emitter.end_mapping
481
479
  end
482
480
 
483
- def format_time time
484
- if time.utc?
481
+ def format_time time, utc = time.utc?
482
+ if utc
485
483
  time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
486
484
  else
487
485
  time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
@@ -535,5 +533,51 @@ module Psych
535
533
  end
536
534
  end
537
535
  end
536
+
537
+ class RestrictedYAMLTree < YAMLTree
538
+ DEFAULT_PERMITTED_CLASSES = {
539
+ TrueClass => true,
540
+ FalseClass => true,
541
+ NilClass => true,
542
+ Integer => true,
543
+ Float => true,
544
+ String => true,
545
+ Array => true,
546
+ Hash => true,
547
+ }.compare_by_identity.freeze
548
+
549
+ def initialize emitter, ss, options
550
+ super
551
+ @permitted_classes = DEFAULT_PERMITTED_CLASSES.dup
552
+ Array(options[:permitted_classes]).each do |klass|
553
+ @permitted_classes[klass] = true
554
+ end
555
+ @permitted_symbols = {}.compare_by_identity
556
+ Array(options[:permitted_symbols]).each do |symbol|
557
+ @permitted_symbols[symbol] = true
558
+ end
559
+ @aliases = options.fetch(:aliases, false)
560
+ end
561
+
562
+ def accept target
563
+ if !@aliases && @st.key?(target)
564
+ raise BadAlias, "Tried to dump an aliased object"
565
+ end
566
+
567
+ unless Symbol === target || @permitted_classes[target.class]
568
+ raise DisallowedClass.new('dump', target.class.name || target.class.inspect)
569
+ end
570
+
571
+ super
572
+ end
573
+
574
+ def visit_Symbol sym
575
+ unless @permitted_classes[Symbol] || @permitted_symbols[sym]
576
+ raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
577
+ end
578
+
579
+ super
580
+ end
581
+ end
538
582
  end
539
583
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/visitors/visitor'
3
- require 'psych/visitors/to_ruby'
4
- require 'psych/visitors/emitter'
5
- require 'psych/visitors/yaml_tree'
6
- require 'psych/visitors/json_tree'
7
- require 'psych/visitors/depth_first'
2
+ require_relative 'visitors/visitor'
3
+ require_relative 'visitors/to_ruby'
4
+ require_relative 'visitors/emitter'
5
+ require_relative 'visitors/yaml_tree'
6
+ require_relative 'visitors/json_tree'
7
+ require_relative 'visitors/depth_first'