psych 4.0.1 → 4.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fa803573d39d69c706eec844ab105ce74589c01fd5284340d353e577829c4e1
4
- data.tar.gz: f5ec2260e1d0d1f2703d6c4cb672235b71754045a95b6a74cc7d12f5b490d0be
3
+ metadata.gz: 247033480f351c6ed0affaedd3b76989d9b08cb72f9502a8ce90992f96ebc180
4
+ data.tar.gz: 55967241dfa777eaaa536c9bab3ab38df842b70107ba2d08e96a8f70196ee9e4
5
5
  SHA512:
6
- metadata.gz: 2127235feecf70da3458afd0cf70a916d5f04e0d7bd659f731ec8f18b8d6438ec4f9c81385ba055029825cd4db28df940db4447cff20ca767b9ebe526753e595
7
- data.tar.gz: 0d8247f8a1cd7a2f9cb260c2dde98abdf7e7d23c6616209e8d06f7245c0eeeb8c17a289d006ae9bf0c5c674f91292c5014b001dfa85d18c92ce85bfc1907bf12
6
+ metadata.gz: a1b85ec41b601fc614174a7bf2e43630b988eeb9cf771c4ecb1fadd1018a05a0b9962ac543a5f7441a3730d7b3f988acaf9a3530a063932f7d742ad6515278cf
7
+ data.tar.gz: 28bf4c4bb7cc8b2455d013226d915ddd84b2d75ac263eba35b852dd1b534bd4572b5104c3f5525b8c73a205f58d419042773d8693aeb9ebe60a50b8f3e077f0b
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  task :sync_tool do
35
35
  require 'fileutils'
36
- FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
36
+ FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
37
37
  FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
38
38
  FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
39
39
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/omap'
3
- require 'psych/set'
2
+ require_relative 'omap'
3
+ require_relative 'set'
4
4
 
5
5
  module Psych
6
6
  class ClassLoader # :nodoc:
@@ -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
@@ -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,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'stringio'
3
- require 'psych/class_loader'
4
- require 'psych/scalar_scanner'
3
+ require_relative '../class_loader'
4
+ require_relative '../scalar_scanner'
5
5
 
6
6
  module Psych
7
7
  module Nodes
@@ -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(symbolize_names: false, freeze: false)
50
- Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self)
49
+ def to_ruby(symbolize_names: false, freeze: false, strict_integer: false)
50
+ Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self)
51
51
  end
52
52
  alias :transform :to_ruby
53
53
 
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
  ###
@@ -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
11
+ # Base 60, [-+]inf and NaN are handled separately
12
+ FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
15
13
 
16
14
  # 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
15
+ INTEGER_STRICT = /^(?:[-+]?0b[0-1_]+ (?# base 2)
16
+ |[-+]?0[0-7_]+ (?# base 8)
17
+ |[-+]?(0|[1-9][0-9_]*) (?# base 10)
18
+ |[-+]?0x[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_,]+ (?# base 2)
23
+ |[-+]?0[0-7_,]+ (?# base 8)
24
+ |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
25
+ |[-+]?0x[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)
@@ -57,11 +63,11 @@ module Psych
57
63
  elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
58
64
  require 'date'
59
65
  begin
60
- class_loader.date.strptime(string, '%Y-%m-%d')
66
+ class_loader.date.strptime(string, '%F', Date::GREGORIAN)
61
67
  rescue ArgumentError
62
68
  string
63
69
  end
64
- elsif string.match?(/^\.inf$/i)
70
+ elsif string.match?(/^\+?\.inf$/i)
65
71
  Float::INFINITY
66
72
  elsif string.match?(/^-\.inf$/i)
67
73
  -Float::INFINITY
@@ -89,9 +95,9 @@ module Psych
89
95
  if string.match?(/\A[-+]?\.\Z/)
90
96
  string
91
97
  else
92
- Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
98
+ Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
93
99
  end
94
- elsif string.match?(INTEGER)
100
+ elsif string.match?(integer_regex)
95
101
  parse_int string
96
102
  else
97
103
  string
@@ -101,7 +107,7 @@ module Psych
101
107
  ###
102
108
  # Parse and return an int from +string+
103
109
  def parse_int string
104
- Integer(string.gsub(/[,_]/, ''))
110
+ Integer(string.delete(',_'))
105
111
  end
106
112
 
107
113
  ###
@@ -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
  ###
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '4.0.1'
5
+ VERSION = '4.0.6'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
- DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '1.33'.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
 
@@ -80,7 +80,9 @@ module Psych
80
80
  when "!ruby/object:DateTime"
81
81
  class_loader.date_time
82
82
  require 'date' unless defined? DateTime
83
- @ss.parse_time(o.value).to_datetime
83
+ t = @ss.parse_time(o.value)
84
+ DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
85
+ (t.subsec/86400)
84
86
  when '!ruby/encoding'
85
87
  ::Encoding.find o.value
86
88
  when "!ruby/object:Complex"
@@ -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
@@ -192,12 +192,13 @@ module Psych
192
192
  register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
193
193
  end
194
194
 
195
+ def visit_Date o
196
+ register o, visit_Integer(o.gregorian)
197
+ end
198
+
195
199
  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
200
+ t = o.italy
201
+ formatted = format_time t, t.offset.zero?
201
202
  tag = '!ruby/object:DateTime'
202
203
  register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY)
203
204
  end
@@ -235,7 +236,6 @@ module Psych
235
236
  end
236
237
  alias :visit_TrueClass :visit_Integer
237
238
  alias :visit_FalseClass :visit_Integer
238
- alias :visit_Date :visit_Integer
239
239
 
240
240
  def visit_Float o
241
241
  if o.nan?
@@ -272,6 +272,8 @@ module Psych
272
272
  tag = 'tag:yaml.org,2002:str'
273
273
  plain = false
274
274
  quote = false
275
+ elsif o == 'y' || o == 'n'
276
+ style = Nodes::Scalar::DOUBLE_QUOTED
275
277
  elsif @line_width && o.length > @line_width
276
278
  style = Nodes::Scalar::FOLDED
277
279
  elsif o =~ /^[^[:word:]][^"]*$/
@@ -480,8 +482,8 @@ module Psych
480
482
  @emitter.end_mapping
481
483
  end
482
484
 
483
- def format_time time
484
- if time.utc?
485
+ def format_time time, utc = time.utc?
486
+ if utc
485
487
  time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
486
488
  else
487
489
  time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
@@ -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'
data/lib/psych.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/versions'
2
+ require_relative 'psych/versions'
3
3
  case RUBY_ENGINE
4
4
  when 'jruby'
5
- require 'psych_jars'
5
+ require_relative 'psych_jars'
6
6
  if JRuby::Util.respond_to?(:load_ext)
7
7
  JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')
8
8
  else
@@ -12,28 +12,28 @@ when 'jruby'
12
12
  else
13
13
  require 'psych.so'
14
14
  end
15
- require 'psych/nodes'
16
- require 'psych/streaming'
17
- require 'psych/visitors'
18
- require 'psych/handler'
19
- require 'psych/tree_builder'
20
- require 'psych/parser'
21
- require 'psych/omap'
22
- require 'psych/set'
23
- require 'psych/coder'
24
- require 'psych/core_ext'
25
- require 'psych/stream'
26
- require 'psych/json/tree_builder'
27
- require 'psych/json/stream'
28
- require 'psych/handlers/document_stream'
29
- require 'psych/class_loader'
15
+ require_relative 'psych/nodes'
16
+ require_relative 'psych/streaming'
17
+ require_relative 'psych/visitors'
18
+ require_relative 'psych/handler'
19
+ require_relative 'psych/tree_builder'
20
+ require_relative 'psych/parser'
21
+ require_relative 'psych/omap'
22
+ require_relative 'psych/set'
23
+ require_relative 'psych/coder'
24
+ require_relative 'psych/core_ext'
25
+ require_relative 'psych/stream'
26
+ require_relative 'psych/json/tree_builder'
27
+ require_relative 'psych/json/stream'
28
+ require_relative 'psych/handlers/document_stream'
29
+ require_relative 'psych/class_loader'
30
30
 
31
31
  ###
32
32
  # = Overview
33
33
  #
34
34
  # Psych is a YAML parser and emitter.
35
35
  # Psych leverages libyaml [Home page: https://pyyaml.org/wiki/LibYAML]
36
- # or [HG repo: https://bitbucket.org/xi/libyaml] for its YAML parsing
36
+ # or [git repo: https://github.com/yaml/libyaml] for its YAML parsing
37
37
  # and emitting capabilities. In addition to wrapping libyaml, Psych also
38
38
  # knows how to serialize and de-serialize most Ruby objects to and from
39
39
  # the YAML format.
@@ -268,12 +268,11 @@ module Psych
268
268
  # YAML documents that are supplied via user input. Instead, please use the
269
269
  # load method or the safe_load method.
270
270
  #
271
- def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false
271
+ def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false, strict_integer: false
272
272
  result = parse(yaml, filename: filename)
273
273
  return fallback unless result
274
- result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
274
+ result.to_ruby(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer)
275
275
  end
276
- class << self; alias :load :unsafe_load; end
277
276
 
278
277
  ###
279
278
  # Safely load the yaml string in +yaml+. By default, only the following
@@ -320,13 +319,13 @@ module Psych
320
319
  # Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"}
321
320
  # Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
322
321
  #
323
- def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
322
+ def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false
324
323
  result = parse(yaml, filename: filename)
325
324
  return fallback unless result
326
325
 
327
326
  class_loader = ClassLoader::Restricted.new(permitted_classes.map(&:to_s),
328
327
  permitted_symbols.map(&:to_s))
329
- scanner = ScalarScanner.new class_loader
328
+ scanner = ScalarScanner.new class_loader, strict_integer: strict_integer
330
329
  visitor = if aliases
331
330
  Visitors::ToRuby.new scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze
332
331
  else
@@ -366,14 +365,15 @@ module Psych
366
365
  # Raises a TypeError when `yaml` parameter is NilClass. This method is
367
366
  # similar to `safe_load` except that `Symbol` objects are allowed by default.
368
367
  #
369
- def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
368
+ def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false
370
369
  safe_load yaml, permitted_classes: permitted_classes,
371
370
  permitted_symbols: permitted_symbols,
372
371
  aliases: aliases,
373
372
  filename: filename,
374
373
  fallback: fallback,
375
374
  symbolize_names: symbolize_names,
376
- freeze: freeze
375
+ freeze: freeze,
376
+ strict_integer: strict_integer
377
377
  end
378
378
 
379
379
  ###
data/psych.gemspec CHANGED
@@ -63,5 +63,7 @@ DESCRIPTION
63
63
  s.add_dependency 'jar-dependencies', '>= 0.1.7'
64
64
  else
65
65
  s.extensions = ["ext/psych/extconf.rb"]
66
+ s.add_dependency 'stringio'
66
67
  end
68
+
67
69
  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: 4.0.1
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-06-07 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2022-09-28 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: stringio
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
15
29
  description: |
16
30
  Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
17
31
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
@@ -117,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
131
  - !ruby/object:Gem::Version
118
132
  version: '0'
119
133
  requirements: []
120
- rubygems_version: 3.2.15
134
+ rubygems_version: 3.4.0.dev
121
135
  signing_key:
122
136
  specification_version: 4
123
137
  summary: Psych is a YAML parser and emitter