You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
string values with leading hyphenated line cause error when converted to YAML #137
Although the original issue was found in ActiveRecord, it can be shown more generally serializing a Hash:
{ 'key' => %{2013-04-08 11:45:33} }.to_yaml # ok
=> "---\nkey: '2013-04-08 11:45:33'\n"
{ 'key' => %{- 2013-04-08 11:45:33} }.to_yaml # ok
=> "---\nkey: ! '- 2013-04-08 11:45:33'\n"
{ 'key' => %{- a\n2013-04-08 11:45:33} }.to_yaml # error
TypeError: can't convert nil into Integer
from ..gems/psych-1.3.4/lib/psych/scalar_scanner.rb:111:in `utc'
from ..gems/psych-1.3.4/lib/psych/scalar_scanner.rb:111:in `parse_time'
# but if the date format parses correctly, it doesn't fail, but the string has been incorrectly converted to yaml:
{ 'key' => %{- a\n2013-04-08 11:45} }.to_yaml
=> "---\nkey: ! '- a\n\n 2013-04-08 11:45'\n"
It seems like the same date handling error in #82 but the real issue (question?) seems to be that the leading '- string\n' sequence is causing psych to try to interpret my text as yaml when in fact it should all be treated as a string literal.
Is this expected behaviour?
Especially in the ActiveRecord case, can we control such behaviour so that user-generated content doesn't unexpectedly break psych?
Activity
hsbt commentedon Jun 12, 2026
This no longer fails on current releases. The string is dumped as a block literal. Closing as resolved.