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..1621f060 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -60,6 +60,17 @@ 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_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