psych 3.0.3.pre3-java → 3.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -105,7 +105,7 @@ module Psych
105
105
  # - first element
106
106
  # - *ponies
107
107
  #
108
- # &ponies is the achor, *ponies is the alias. In this case, alias is
108
+ # &ponies is the anchor, *ponies is the alias. In this case, alias is
109
109
  # called with "ponies".
110
110
  def alias anchor
111
111
  end
@@ -46,8 +46,8 @@ module Psych
46
46
  # Convert this node to Ruby.
47
47
  #
48
48
  # See also Psych::Visitors::ToRuby
49
- def to_ruby
50
- Visitors::ToRuby.create.accept(self)
49
+ def to_ruby(symbolize_names: false, freeze: false)
50
+ Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self)
51
51
  end
52
52
  alias :transform :to_ruby
53
53
 
@@ -14,16 +14,15 @@ module Psych
14
14
  |\.(nan|NaN|NAN)(?# not a number))$/x
15
15
 
16
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
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
21
21
 
22
22
  attr_reader :class_loader
23
23
 
24
24
  # Create a new scanner
25
25
  def initialize class_loader
26
- @string_cache = {}
27
26
  @symbol_cache = {}
28
27
  @class_loader = class_loader
29
28
  end
@@ -31,81 +30,70 @@ module Psych
31
30
  # Tokenize +string+ returning the Ruby object
32
31
  def tokenize string
33
32
  return nil if string.empty?
34
- return string if @string_cache.key?(string)
35
33
  return @symbol_cache[string] if @symbol_cache.key?(string)
36
34
 
37
- case string
38
35
  # Check for a String type, being careful not to get caught by hash keys, hex values, and
39
36
  # special floats (e.g., -.inf).
40
- when /^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/, /\n/
41
- if string.length > 5
42
- @string_cache[string] = true
43
- return string
44
- end
37
+ if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
38
+ return string if string.length > 5
45
39
 
46
- case string
47
- when /^[^ytonf~]/i
48
- @string_cache[string] = true
40
+ if string.match?(/^[^ytonf~]/i)
49
41
  string
50
- when '~', /^null$/i
42
+ elsif string == '~' || string.match?(/^null$/i)
51
43
  nil
52
- when /^(yes|true|on)$/i
44
+ elsif string.match?(/^(yes|true|on)$/i)
53
45
  true
54
- when /^(no|false|off)$/i
46
+ elsif string.match?(/^(no|false|off)$/i)
55
47
  false
56
48
  else
57
- @string_cache[string] = true
58
49
  string
59
50
  end
60
- when TIME
51
+ elsif string.match?(TIME)
61
52
  begin
62
53
  parse_time string
63
54
  rescue ArgumentError
64
55
  string
65
56
  end
66
- when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/
57
+ elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
67
58
  require 'date'
68
59
  begin
69
60
  class_loader.date.strptime(string, '%Y-%m-%d')
70
61
  rescue ArgumentError
71
62
  string
72
63
  end
73
- when /^\.inf$/i
64
+ elsif string.match?(/^\.inf$/i)
74
65
  Float::INFINITY
75
- when /^-\.inf$/i
66
+ elsif string.match?(/^-\.inf$/i)
76
67
  -Float::INFINITY
77
- when /^\.nan$/i
68
+ elsif string.match?(/^\.nan$/i)
78
69
  Float::NAN
79
- when /^:./
70
+ elsif string.match?(/^:./)
80
71
  if string =~ /^:(["'])(.*)\1/
81
72
  @symbol_cache[string] = class_loader.symbolize($2.sub(/^:/, ''))
82
73
  else
83
74
  @symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
84
75
  end
85
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/
76
+ elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/)
86
77
  i = 0
87
78
  string.split(':').each_with_index do |n,e|
88
79
  i += (n.to_i * 60 ** (e - 2).abs)
89
80
  end
90
81
  i
91
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/
82
+ elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/)
92
83
  i = 0
93
84
  string.split(':').each_with_index do |n,e|
94
85
  i += (n.to_f * 60 ** (e - 2).abs)
95
86
  end
96
87
  i
97
- when FLOAT
98
- if string =~ /\A[-+]?\.\Z/
99
- @string_cache[string] = true
88
+ elsif string.match?(FLOAT)
89
+ if string.match?(/\A[-+]?\.\Z/)
100
90
  string
101
91
  else
102
92
  Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
103
93
  end
94
+ elsif string.match?(INTEGER)
95
+ parse_int string
104
96
  else
105
- int = parse_int string.gsub(/[,_]/, '')
106
- return int if int
107
-
108
- @string_cache[string] = true
109
97
  string
110
98
  end
111
99
  end
@@ -113,8 +101,7 @@ module Psych
113
101
  ###
114
102
  # Parse and return an int from +string+
115
103
  def parse_int string
116
- return unless INTEGER === string
117
- Integer(string)
104
+ Integer(string.gsub(/[,_]/, ''))
118
105
  end
119
106
 
120
107
  ###
@@ -1,9 +1,10 @@
1
+
1
2
  # frozen_string_literal: true
2
3
  module Psych
3
- # The version is Psych you're using
4
- VERSION = '3.0.3.pre3'
4
+ # The version of Psych you are using
5
+ VERSION = '3.2.1'
5
6
 
6
7
  if RUBY_ENGINE == 'jruby'
7
- DEFAULT_SNAKEYAML_VERSION = '1.23'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '1.26'.freeze
8
9
  end
9
10
  end
@@ -12,34 +12,38 @@ 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
15
+ def self.create(symbolize_names: false, freeze: false)
16
16
  class_loader = ClassLoader.new
17
17
  scanner = ScalarScanner.new class_loader
18
- new(scanner, class_loader)
18
+ new(scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze)
19
19
  end
20
20
 
21
21
  attr_reader :class_loader
22
22
 
23
- def initialize ss, class_loader
23
+ def initialize ss, class_loader, symbolize_names: false, freeze: false
24
24
  super()
25
25
  @st = {}
26
26
  @ss = ss
27
27
  @domain_types = Psych.domain_types
28
28
  @class_loader = class_loader
29
+ @symbolize_names = symbolize_names
30
+ @freeze = freeze
29
31
  end
30
32
 
31
33
  def accept target
32
34
  result = super
33
- return result if @domain_types.empty? || !target.tag
34
35
 
35
- key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
36
- key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
36
+ unless @domain_types.empty? || !target.tag
37
+ key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
38
+ key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
37
39
 
38
- if @domain_types.key? key
39
- value, block = @domain_types[key]
40
- return block.call value, result
40
+ if @domain_types.key? key
41
+ value, block = @domain_types[key]
42
+ result = block.call value, result
43
+ end
41
44
  end
42
45
 
46
+ result = deduplicate(result).freeze if @freeze
43
47
  result
44
48
  end
45
49
 
@@ -252,6 +256,8 @@ module Psych
252
256
 
253
257
  e = build_exception((resolve_class($1) || class_loader.exception),
254
258
  h.delete('message'))
259
+
260
+ e.set_backtrace h.delete('backtrace') if h.key? 'backtrace'
255
261
  init_with(e, h, o)
256
262
 
257
263
  when '!set', 'tag:yaml.org,2002:set'
@@ -331,13 +337,12 @@ module Psych
331
337
  list
332
338
  end
333
339
 
334
- SHOVEL = '<<'
335
340
  def revive_hash hash, o
336
341
  o.children.each_slice(2) { |k,v|
337
342
  key = accept(k)
338
343
  val = accept(v)
339
344
 
340
- if key == SHOVEL && k.tag != "tag:yaml.org,2002:str"
345
+ if key == '<<' && k.tag != "tag:yaml.org,2002:str"
341
346
  case v
342
347
  when Nodes::Alias, Nodes::Mapping
343
348
  begin
@@ -359,6 +364,12 @@ module Psych
359
364
  hash[key] = val
360
365
  end
361
366
  else
367
+ if @symbolize_names
368
+ key = key.to_sym
369
+ elsif !@freeze
370
+ key = deduplicate(key)
371
+ end
372
+
362
373
  hash[key] = val
363
374
  end
364
375
 
@@ -366,6 +377,26 @@ module Psych
366
377
  hash
367
378
  end
368
379
 
380
+ if RUBY_VERSION < '2.7'
381
+ def deduplicate key
382
+ if key.is_a?(String)
383
+ # It is important to untaint the string, otherwise it won't
384
+ # be deduplicated into an fstring, but simply frozen.
385
+ -(key.untaint)
386
+ else
387
+ key
388
+ end
389
+ end
390
+ else
391
+ def deduplicate key
392
+ if key.is_a?(String)
393
+ -key
394
+ else
395
+ key
396
+ end
397
+ end
398
+ end
399
+
369
400
  def merge_key hash, key, val
370
401
  end
371
402
 
@@ -181,41 +181,11 @@ module Psych
181
181
  end
182
182
 
183
183
  def visit_Exception o
184
- tag = ['!ruby/exception', o.class.name].join ':'
185
-
186
- @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
187
-
188
- {
189
- 'message' => private_iv_get(o, 'mesg'),
190
- 'backtrace' => private_iv_get(o, 'backtrace'),
191
- }.each do |k,v|
192
- next unless v
193
- @emitter.scalar k, nil, nil, true, false, Nodes::Scalar::ANY
194
- accept v
195
- end
196
-
197
- dump_ivars o
198
-
199
- @emitter.end_mapping
184
+ dump_exception o, o.message.to_s
200
185
  end
201
186
 
202
187
  def visit_NameError o
203
- tag = ['!ruby/exception', o.class.name].join ':'
204
-
205
- @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
206
-
207
- {
208
- 'message' => o.message.to_s,
209
- 'backtrace' => private_iv_get(o, 'backtrace'),
210
- }.each do |k,v|
211
- next unless v
212
- @emitter.scalar k, nil, nil, true, false, Nodes::Scalar::ANY
213
- accept v
214
- end
215
-
216
- dump_ivars o
217
-
218
- @emitter.end_mapping
188
+ dump_exception o, o.message.to_s
219
189
  end
220
190
 
221
191
  def visit_Regexp o
@@ -458,15 +428,6 @@ module Psych
458
428
  node = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
459
429
  register(o, node)
460
430
 
461
- # Dump the elements
462
- accept 'elements'
463
- @emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
464
- o.each do |k,v|
465
- accept k
466
- accept v
467
- end
468
- @emitter.end_mapping
469
-
470
431
  # Dump the ivars
471
432
  accept 'ivars'
472
433
  @emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
@@ -476,6 +437,15 @@ module Psych
476
437
  end
477
438
  @emitter.end_mapping
478
439
 
440
+ # Dump the elements
441
+ accept 'elements'
442
+ @emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
443
+ o.each do |k,v|
444
+ accept k
445
+ accept v
446
+ end
447
+ @emitter.end_mapping
448
+
479
449
  @emitter.end_mapping
480
450
  else
481
451
  tag = "!ruby/hash:#{o.class}"
@@ -492,6 +462,24 @@ module Psych
492
462
  def dump_list o
493
463
  end
494
464
 
465
+ def dump_exception o, msg
466
+ tag = ['!ruby/exception', o.class.name].join ':'
467
+
468
+ @emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
469
+
470
+ if msg
471
+ @emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
472
+ accept msg
473
+ end
474
+
475
+ @emitter.scalar 'backtrace', nil, nil, true, false, Nodes::Scalar::ANY
476
+ accept o.backtrace
477
+
478
+ dump_ivars o
479
+
480
+ @emitter.end_mapping
481
+ end
482
+
495
483
  def format_time time
496
484
  if time.utc?
497
485
  time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
@@ -1,14 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
3
 
4
+ version_module = Module.new do
5
+ version_rb = File.join(__dir__, "lib/psych/versions.rb")
6
+ module_eval(File.read(version_rb), version_rb)
7
+ end
8
+
4
9
  Gem::Specification.new do |s|
5
10
  s.name = "psych"
6
- s.version = "3.0.3.pre3"
11
+ s.version = version_module::Psych::VERSION
7
12
  s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"]
8
13
  s.email = ["aaron@tenderlovemaking.com", "hsbt@ruby-lang.org", "headius@headius.com"]
9
14
  s.summary = "Psych is a YAML parser and emitter"
10
15
  s.description = <<-DESCRIPTION
11
- Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML]
16
+ Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
12
17
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
13
18
  Psych also knows how to serialize and de-serialize most Ruby objects to and from the YAML format.
14
19
  DESCRIPTION
@@ -18,7 +23,7 @@ DESCRIPTION
18
23
 
19
24
  # for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
25
  s.files = [
21
- ".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console",
26
+ ".gitignore", "Gemfile", "LICENSE", "Mavenfile", "README.md", "Rakefile", "bin/console",
22
27
  "bin/setup", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h",
23
28
  "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h",
24
29
  "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h",
@@ -38,26 +43,25 @@ DESCRIPTION
38
43
  ]
39
44
 
40
45
  s.rdoc_options = ["--main", "README.md"]
41
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"]
46
+ s.extra_rdoc_files = ["README.md"]
42
47
 
43
- s.required_ruby_version = Gem::Requirement.new(">= 2.2.2")
44
- s.rubygems_version = "2.5.1"
48
+ s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
45
49
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
46
50
 
47
- s.add_development_dependency 'rake-compiler', ">= 0.4.1"
48
- s.add_development_dependency 'minitest', "~> 5.0"
49
-
50
51
  if RUBY_ENGINE == 'jruby'
51
52
  s.platform = 'java'
52
53
  s.files.concat [
53
- "ext/java/PsychEmitter.java", "ext/java/PsychLibrary.java", "ext/java/PsychParser.java", "ext/java/PsychToRuby.java",
54
- "ext/java/PsychYamlTree.java", "lib/psych_jars.rb", "lib/psych.jar"
54
+ "ext/java/org/jruby/ext/psych/PsychEmitter.java",
55
+ "ext/java/org/jruby/ext/psych/PsychLibrary.java",
56
+ "ext/java/org/jruby/ext/psych/PsychParser.java",
57
+ "ext/java/org/jruby/ext/psych/PsychToRuby.java",
58
+ "ext/java/org/jruby/ext/psych/PsychYamlTree.java",
59
+ "lib/psych_jars.rb",
60
+ "lib/psych.jar"
55
61
  ]
56
- s.requirements = "jar org.yaml:snakeyaml, 1.23"
62
+ s.requirements = "jar org.yaml:snakeyaml, #{version_module::Psych::DEFAULT_SNAKEYAML_VERSION}"
57
63
  s.add_dependency 'jar-dependencies', '>= 0.1.7'
58
- s.add_development_dependency 'ruby-maven'
59
64
  else
60
65
  s.extensions = ["ext/psych/extconf.rb"]
61
- s.add_development_dependency 'rake-compiler-dock', ">= 0.6.1"
62
66
  end
63
67
  end
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.0.3.pre3
4
+ version: 3.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,36 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-10-12 00:00:00.000000000 Z
13
+ date: 2020-12-14 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 0.4.1
21
- name: rake-compiler
22
- prerelease: false
23
- type: :development
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 0.4.1
29
- - !ruby/object:Gem::Dependency
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '5.0'
35
- name: minitest
36
- prerelease: false
37
- type: :development
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '5.0'
43
15
  - !ruby/object:Gem::Dependency
44
16
  requirement: !ruby/object:Gem::Requirement
45
17
  requirements:
@@ -47,29 +19,15 @@ dependencies:
47
19
  - !ruby/object:Gem::Version
48
20
  version: 0.1.7
49
21
  name: jar-dependencies
50
- prerelease: false
51
22
  type: :runtime
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.1.7
57
- - !ruby/object:Gem::Dependency
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- name: ruby-maven
64
23
  prerelease: false
65
- type: :development
66
24
  version_requirements: !ruby/object:Gem::Requirement
67
25
  requirements:
68
26
  - - ">="
69
27
  - !ruby/object:Gem::Version
70
- version: '0'
28
+ version: 0.1.7
71
29
  description: |
72
- Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML]
30
+ Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
73
31
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
74
32
  Psych also knows how to serialize and de-serialize most Ruby objects to and from the YAML format.
75
33
  email:
@@ -79,23 +37,21 @@ email:
79
37
  executables: []
80
38
  extensions: []
81
39
  extra_rdoc_files:
82
- - CHANGELOG.rdoc
83
40
  - README.md
84
41
  files:
85
42
  - ".gitignore"
86
- - ".travis.yml"
87
- - CHANGELOG.rdoc
88
43
  - Gemfile
44
+ - LICENSE
89
45
  - Mavenfile
90
46
  - README.md
91
47
  - Rakefile
92
48
  - bin/console
93
49
  - bin/setup
94
- - ext/java/PsychEmitter.java
95
- - ext/java/PsychLibrary.java
96
- - ext/java/PsychParser.java
97
- - ext/java/PsychToRuby.java
98
- - ext/java/PsychYamlTree.java
50
+ - ext/java/org/jruby/ext/psych/PsychEmitter.java
51
+ - ext/java/org/jruby/ext/psych/PsychLibrary.java
52
+ - ext/java/org/jruby/ext/psych/PsychParser.java
53
+ - ext/java/org/jruby/ext/psych/PsychToRuby.java
54
+ - ext/java/org/jruby/ext/psych/PsychYamlTree.java
99
55
  - ext/psych/depend
100
56
  - ext/psych/extconf.rb
101
57
  - ext/psych/psych.c
@@ -174,16 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
130
  requirements:
175
131
  - - ">="
176
132
  - !ruby/object:Gem::Version
177
- version: 2.2.2
133
+ version: 2.4.0
178
134
  required_rubygems_version: !ruby/object:Gem::Requirement
179
135
  requirements:
180
136
  - - ">="
181
137
  - !ruby/object:Gem::Version
182
138
  version: '0'
183
139
  requirements:
184
- - jar org.yaml:snakeyaml, 1.23
185
- rubyforge_project:
186
- rubygems_version: 2.7.6
140
+ - jar org.yaml:snakeyaml, 1.26
141
+ rubygems_version: 3.0.6
187
142
  signing_key:
188
143
  specification_version: 4
189
144
  summary: Psych is a YAML parser and emitter