diff options
author | Thierry Deo <[email protected]> | 2024-11-13 09:07:06 +0100 |
---|---|---|
committer | git <[email protected]> | 2024-11-20 16:59:55 +0000 |
commit | 2bf5d26eb9eac56cef326d470fb7bd50261df7fe (patch) | |
tree | 7a215ae142089c2717085da35e46309d2831601a | |
parent | 577e6a3e191ce7fdbf9b3a4bdc7ea7cea9e70855 (diff) |
[ruby/psych] Eagerly require `date`.
https://github.com/ruby/psych/commit/b2aa0032c0
-rw-r--r-- | ext/psych/lib/psych.rb | 2 | ||||
-rw-r--r-- | ext/psych/lib/psych/scalar_scanner.rb | 2 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 1 | ||||
-rw-r--r-- | ext/psych/psych.gemspec | 2 | ||||
-rw-r--r-- | test/psych/helper.rb | 1 | ||||
-rw-r--r-- | test/psych/test_date_time.rb | 1 | ||||
-rw-r--r-- | test/psych/test_scalar_scanner.rb | 1 | ||||
-rw-r--r-- | test/psych/test_string.rb | 10 |
8 files changed, 14 insertions, 6 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index d227b1f225..05a3f9c99b 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +require 'date' + require_relative 'psych/versions' case RUBY_ENGINE when 'jruby' diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb index de21442344..8cf868f863 100644 --- a/ext/psych/lib/psych/scalar_scanner.rb +++ b/ext/psych/lib/psych/scalar_scanner.rb @@ -4,8 +4,6 @@ module Psych ### # Scan scalars for built in types class ScalarScanner - autoload :Date, "date" - # Taken from http://yaml.org/type/timestamp.html 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)?))?$/ diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 9e4da5ef0d..f0b4a94e45 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -79,7 +79,6 @@ module Psych class_loader.big_decimal._load o.value when "!ruby/object:DateTime" class_loader.date_time - require 'date' unless defined? DateTime t = @ss.parse_time(o.value) DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) + (t.subsec/86400) diff --git a/ext/psych/psych.gemspec b/ext/psych/psych.gemspec index a3fc53a8b9..a32f79bc16 100644 --- a/ext/psych/psych.gemspec +++ b/ext/psych/psych.gemspec @@ -75,6 +75,8 @@ DESCRIPTION s.add_dependency 'stringio' end + s.add_dependency 'date' + s.metadata['msys2_mingw_dependencies'] = 'libyaml' s.metadata['changelog_uri'] = s.homepage + '/releases' end diff --git a/test/psych/helper.rb b/test/psych/helper.rb index 4e82887c6d..639f6055ff 100644 --- a/test/psych/helper.rb +++ b/test/psych/helper.rb @@ -2,7 +2,6 @@ require 'test/unit' require 'stringio' require 'tempfile' -require 'date' require 'psych' diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index 3379bd24bf..4565b8e764 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require_relative 'helper' -require 'date' module Psych class TestDateTime < TestCase diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index 8907d1255a..2637a74df8 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require_relative 'helper' -require 'date' module Psych class TestScalarScanner < TestCase diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 84ae5cbb45..cfd235a519 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -50,6 +50,16 @@ module Psych assert_equal str, Psych.load(yaml) end + def test_single_quote_when_matching_date + pend "Failing on JRuby" if RUBY_PLATFORM =~ /java/ + + lib = File.expand_path("../../../lib", __FILE__) + assert_separately(["-I", lib, "-r", "psych"], __FILE__, __LINE__ + 1, <<~'RUBY') + yml = Psych.dump('2024-11-19') + assert_equal '2024-11-19', Psych.load(yml) + RUBY + end + def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12 |