Skip to content

Commit 8cf52fa

Browse files
committed
Fix Time.xmlschema handling leading and trailing whitespaces
1 parent 2b43839 commit 8cf52fa

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def rfc3339(time)
670670
if RUBY_VERSION >= "3.2"
671671
def _xmlschema(pattern, time) # :nodoc:
672672
if pattern.match?(time)
673-
new(time)
673+
new(time.strip)
674674
else
675675
raise ArgumentError.new("invalid xmlschema format: #{time.inspect}")
676676
end

test/test_time.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ def subtest_xmlschema_encode(method)
245245
assert_equal("-10000-01-01T00:00:00Z", Time.utc(-10000).__send__(method))
246246
end
247247

248+
def subtest_xmlschema_whitespaces(method)
249+
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
250+
s = " \t 1985-04-12T23:20:50.52Z"
251+
assert_equal(t, Time.__send__(method, s))
252+
253+
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
254+
s = "1985-04-12T23:20:50.52Z \t "
255+
assert_equal(t, Time.__send__(method, s))
256+
end
257+
248258
def test_completion
249259
now = Time.local(2001,11,29,21,26,35)
250260
assert_equal(Time.local( 2001,11,29,21,12),

0 commit comments

Comments
 (0)