Skip to content

Commit 2bf5d26

Browse files
tdeomatzbot
authored andcommitted
[ruby/psych] Eagerly require date.
ruby/psych@b2aa0032c0
1 parent 577e6a3 commit 2bf5d26

File tree

8 files changed

+14
-6
lines changed

8 files changed

+14
-6
lines changed

ext/psych/lib/psych.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# frozen_string_literal: true
2+
require 'date'
3+
24
require_relative 'psych/versions'
35
case RUBY_ENGINE
46
when 'jruby'

ext/psych/lib/psych/scalar_scanner.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ module Psych
44
###
55
# Scan scalars for built in types
66
class ScalarScanner
7-
autoload :Date, "date"
8-
97
# Taken from http://yaml.org/type/timestamp.html
108
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)?))?$/
119

ext/psych/lib/psych/visitors/to_ruby.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def deserialize o
7979
class_loader.big_decimal._load o.value
8080
when "!ruby/object:DateTime"
8181
class_loader.date_time
82-
require 'date' unless defined? DateTime
8382
t = @ss.parse_time(o.value)
8483
DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
8584
(t.subsec/86400)

ext/psych/psych.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ DESCRIPTION
7575
s.add_dependency 'stringio'
7676
end
7777

78+
s.add_dependency 'date'
79+
7880
s.metadata['msys2_mingw_dependencies'] = 'libyaml'
7981
s.metadata['changelog_uri'] = s.homepage + '/releases'
8082
end

test/psych/helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require 'test/unit'
33
require 'stringio'
44
require 'tempfile'
5-
require 'date'
65

76
require 'psych'
87

test/psych/test_date_time.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22
require_relative 'helper'
3-
require 'date'
43

54
module Psych
65
class TestDateTime < TestCase

test/psych/test_scalar_scanner.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22
require_relative 'helper'
3-
require 'date'
43

54
module Psych
65
class TestScalarScanner < TestCase

test/psych/test_string.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ def test_doublequotes_when_there_is_a_single
5050
assert_equal str, Psych.load(yaml)
5151
end
5252

53+
def test_single_quote_when_matching_date
54+
pend "Failing on JRuby" if RUBY_PLATFORM =~ /java/
55+
56+
lib = File.expand_path("../../../lib", __FILE__)
57+
assert_separately(["-I", lib, "-r", "psych"], __FILE__, __LINE__ + 1, <<~'RUBY')
58+
yml = Psych.dump('2024-11-19')
59+
assert_equal '2024-11-19', Psych.load(yml)
60+
RUBY
61+
end
62+
5363
def test_plain_when_shorten_than_line_width_and_no_final_line_break
5464
str = "Lorem ipsum"
5565
yaml = Psych.dump str, line_width: 12

0 commit comments

Comments
 (0)