Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string values with leading hyphenated line cause error when converted to YAML #137

Open
tardate opened this issue Apr 8, 2013 · 0 comments

Comments

@tardate
Copy link

tardate commented Apr 8, 2013

I ran into this issue with psych 1.3.4 with ActiveRecord models where string attributes contained something that 'looks like' YAML.

item = Item.last
item.description = %{- a\n2013-04-08 11:45:33}
item.to_yaml # error

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant