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 +4 -4
- data/Rakefile +1 -1
- data/lib/psych/class_loader.rb +2 -2
- data/lib/psych/core_ext.rb +1 -1
- data/lib/psych/handlers/document_stream.rb +1 -1
- data/lib/psych/handlers/recorder.rb +1 -1
- data/lib/psych/json/stream.rb +2 -2
- data/lib/psych/json/tree_builder.rb +1 -1
- data/lib/psych/nodes/node.rb +4 -4
- data/lib/psych/nodes.rb +7 -7
- data/lib/psych/scalar_scanner.rb +22 -16
- data/lib/psych/syntax_error.rb +1 -1
- data/lib/psych/tree_builder.rb +1 -1
- data/lib/psych/versions.rb +2 -2
- data/lib/psych/visitors/json_tree.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +8 -6
- data/lib/psych/visitors/yaml_tree.rb +13 -11
- data/lib/psych/visitors.rb +6 -6
- data/lib/psych.rb +25 -25
- data/psych.gemspec +2 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247033480f351c6ed0affaedd3b76989d9b08cb72f9502a8ce90992f96ebc180
|
4
|
+
data.tar.gz: 55967241dfa777eaaa536c9bab3ab38df842b70107ba2d08e96a8f70196ee9e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
data/lib/psych/class_loader.rb
CHANGED
data/lib/psych/core_ext.rb
CHANGED
data/lib/psych/json/stream.rb
CHANGED
data/lib/psych/nodes/node.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'stringio'
|
3
|
-
|
4
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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/scalar_scanner.rb
CHANGED
@@ -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
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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?(
|
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, '%
|
66
|
+
class_loader.date.strptime(string, '%F', Date::GREGORIAN)
|
61
67
|
rescue ArgumentError
|
62
68
|
string
|
63
69
|
end
|
64
|
-
elsif string.match?(
|
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.
|
98
|
+
Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
|
93
99
|
end
|
94
|
-
elsif string.match?(
|
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.
|
110
|
+
Integer(string.delete(',_'))
|
105
111
|
end
|
106
112
|
|
107
113
|
###
|
data/lib/psych/syntax_error.rb
CHANGED
data/lib/psych/tree_builder.rb
CHANGED
data/lib/psych/versions.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
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)
|
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
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
197
|
-
|
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
|
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")
|
data/lib/psych/visitors.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
2
|
+
require_relative 'psych/versions'
|
3
3
|
case RUBY_ENGINE
|
4
4
|
when 'jruby'
|
5
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 [
|
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
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.
|
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:
|
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.
|
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
|