From 8e04d847f59143183726e1ed2c0aec0c1d66bbd2 Mon Sep 17 00:00:00 2001 From: Vasil Nesterov Date: Mon, 24 Nov 2025 14:48:26 +0100 Subject: [PATCH 1/2] Fix parsing of strings with tab-separated datetime --- lib/psych/scalar_scanner.rb | 2 +- test/psych/test_string.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index 6a556fb3..d744e611 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -115,7 +115,7 @@ def parse_int string def parse_time string klass = class_loader.load 'Time' - date, time = *(string.split(/[ tT]/, 2)) + date, time = *(string.split(/[Tt]|\s+/, 2)) (yy, m, dd) = date.match(/^(-?\d{4})-(\d{1,2})-(\d{1,2})/).captures.map { |x| x.to_i } md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/) diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 73fb3933..19fc3bb1 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -60,6 +60,11 @@ def test_single_quote_when_matching_date RUBY end + def test_datetime_string_with_tab_separator + str = "2023-12-31\t12:00:00" + assert_cycle str + end + def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12 From a4f2fc39b005bdaea0249a5cec7bd31df53b9a52 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 12 Jun 2026 11:44:48 +0900 Subject: [PATCH 2/2] Test other whitespace separators in datetime-like strings The TIME pattern accepts any whitespace run between date and time, so cover vertical tab, carriage return, form feed, and mixed separators in addition to the plain tab case. https://github.com/ruby/psych/issues/691 --- test/psych/test_string.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 19fc3bb1..1621f060 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -65,6 +65,12 @@ def test_datetime_string_with_tab_separator assert_cycle str end + def test_datetime_string_with_whitespace_separators + ["\v", "\r", "\f", " \t", "\t "].each do |sep| + assert_cycle "2023-12-31#{sep}12:00:00" + end + end + def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12