psych icon indicating copy to clipboard operation
psych copied to clipboard

Error when serializing date string with non-space whitespace character

Open kkan opened this issue 1 year ago • 0 comments

string = "2023-12-30\t23:16:25"
Psych.dump(string)
/.rbenv/versions/3.2.2/lib/ruby/3.2.0/psych/scalar_scanner.rb:120:in `parse_time': undefined method `match' for nil:NilClass (NoMethodError)

      md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)

Happens because \s is used in TIME regex, and space is used when splitting string into date and time

string.match?(Psych::ScalarScanner::TIME) # true
date, time = *(string.split(/[ tT]/, 2)) # ["2023-12-30\t23:16:25"]

kkan avatar Oct 16 '24 15:10 kkan