jnunemaker / crack

Really simple JSON and XML parsing, ripped from Merb and Rails.
MIT License
541 stars 93 forks source link

Add optional test for psych parser and fix for psych parsing error. #32

Closed matt-glover closed 11 years ago

matt-glover commented 13 years ago

When using the Crack gem with ruby 1.9.2 you may see Psych::Syntax errors bubble up through the gem (see issue 29 https://github.com/jnunemaker/crack/issues/29) and to the calling code. This pull request attempts to demonstrate that issue via a psych test (which is only executed when your machine is configured to support psych) and a potential fix for that issue.

When you build ruby 1.9.2 with libyaml on your system ruby automatically includes the psych YAML parser as the default instead of syck which is used in previous versions of ruby (and those machines building ruby without libyaml). The error bubbled up from syck when bogus YAML is provided, which crack catches and wraps, is an argument error. The error bubbled up from psych is a derivative of the SyntaxError type.

So the fix was to catch both error types since the syck parser is currently in use and needs to be supported at least for a while but it is no longer being maintained and presumably will not be used by default in some future release of ruby.

jnunemaker commented 11 years ago

Closing this due to age and neglect on my part.