psych 4.0.3 → 4.0.4

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: 1369793b13011e838e482cd74a90f8ad91dca42331cbbd12fc9f6a9b94aec5b6
4
- data.tar.gz: 3552d1df84ad75f3662eff7bf1d824d706304288aa253627212265d311069198
3
+ metadata.gz: c7feb4df24f58d2d6f2c8fb8d7ea5ab70f2c42a60b9abb8d3fb9196d0591ffe1
4
+ data.tar.gz: 2f20dbfc2a70e7ee08d220a029c729e51aa4245318680cc65ec08ddba639894f
5
5
  SHA512:
6
- metadata.gz: bc828b1cb2e72cb28366bfe22c3ddc320cf30723da7268af66cfef39d3f4f70310f07af224407f1e34a18ea0c00e6c6bc533299b3d20e4c7effdad00bf689e72
7
- data.tar.gz: 4817b1702fe5fc7a659fc1156342630bee265c644074ea15859b32c8ebbb446db837bd68e004f8a1e13c11c860f67e8215fcfe4be609187e0986f2a94f102793
6
+ metadata.gz: 517352bc229d00418119d8123457f692063f48a72663db1ec4daad04161dc84ad3ae6b15722ac63129f4b6cee2d324fc77c522ac463a4bd9ba664286ccdbb62f
7
+ data.tar.gz: 87411fceb103e660919a5a58844e83e88209f805abd2109c8e3d6145736c41b27d85808ca9d454c51380c7d0cf1a6428937f85c81ef1cb2d47b10b7ef9720c7a
@@ -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
 
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'strscan'
3
2
 
4
3
  module Psych
5
4
  ###
@@ -13,24 +12,32 @@ module Psych
13
12
  FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
14
13
 
15
14
  # Taken from http://yaml.org/type/int.html
16
- INTEGER = /^(?:[-+]?0b[0-1_,]+ (?# base 2)
17
- |[-+]?0[0-7_,]+ (?# base 8)
18
- |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
19
- |[-+]?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
20
26
 
21
27
  attr_reader :class_loader
22
28
 
23
29
  # Create a new scanner
24
- def initialize class_loader
30
+ def initialize class_loader, strict_integer: false
25
31
  @symbol_cache = {}
26
32
  @class_loader = class_loader
33
+ @strict_integer = strict_integer
27
34
  end
28
35
 
29
36
  # Tokenize +string+ returning the Ruby object
30
37
  def tokenize string
31
38
  return nil if string.empty?
32
39
  return @symbol_cache[string] if @symbol_cache.key?(string)
33
-
40
+ integer_regex = @strict_integer ? INTEGER_STRICT : INTEGER_LEGACY
34
41
  # Check for a String type, being careful not to get caught by hash keys, hex values, and
35
42
  # special floats (e.g., -.inf).
36
43
  if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
@@ -88,9 +95,9 @@ module Psych
88
95
  if string.match?(/\A[-+]?\.\Z/)
89
96
  string
90
97
  else
91
- Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
98
+ Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
92
99
  end
93
- elsif string.match?(INTEGER)
100
+ elsif string.match?(integer_regex)
94
101
  parse_int string
95
102
  else
96
103
  string
@@ -100,7 +107,7 @@ module Psych
100
107
  ###
101
108
  # Parse and return an int from +string+
102
109
  def parse_int string
103
- Integer(string.gsub(/[,_]/, ''))
110
+ Integer(string.delete(',_'))
104
111
  end
105
112
 
106
113
  ###
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '4.0.3'
5
+ VERSION = '4.0.4'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
8
  DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze
@@ -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
 
data/lib/psych.rb CHANGED
@@ -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
  ###
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.3
4
+ version: 4.0.4
5
5
  platform: ruby
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: 2021-12-20 00:00:00.000000000 Z
13
+ date: 2022-05-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: stringio
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.3.0.dev
134
+ rubygems_version: 3.4.0.dev
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Psych is a YAML parser and emitter