YAML Broken?

Folks,

It seems that when I YAML.dump arrays that contain long strings that
contain non-printables and sometimes UTF-8 sequences, the YAML’ed
objects can’t be read back in. Is this a known issue? If so, is
there a known work-around? Alternatively, are there any other ways to
serialize objects (JSON doesn’t work because eval() barfs on very long
strings)?

Thanks,

David

David P. wrote:

David

There’s always Marshal.

http://ruby-doc.org/core/classes/Marshal.html

-Justin

On Wed, 26 Jul 2006, David P. wrote:

David

can you show an example?

harp:~ > ruby -r yaml -e’ nul = 0.chr; y(YAML.load(YAML.dump(nul))
== nul) ’
true

harp:~ > ruby -v
ruby 1.8.4 (2005-12-01) [i686-linux]

-a

David P. wrote:

Folks,

It seems that when I YAML.dump arrays that contain long strings that
contain non-printables and sometimes UTF-8 sequences, the YAML’ed
objects can’t be read back in. Is this a known issue? If so, is
there a known work-around? Alternatively, are there any other ways to
serialize objects (JSON doesn’t work because eval() barfs on very long
strings)?
If you’re on Windows, check you’re reading and writing in binary mode…
Not sure if that’s what’ll be causing your problem, but it’s tripped
me up before.

Thanks!

It seems that when I YAML.dump arrays that contain long strings that
contain non-printables and sometimes UTF-8 sequences, the YAML’ed
objects can’t be read back in. Is this a known issue? If so, is
there a known work-around? Alternatively, are there any other ways to
serialize objects (JSON doesn’t work because eval() barfs on very long
strings)?
I’ve had that in one of my rails projects. Luckily it was for a cache,
and
it only happened sporadically. So my solution was to catch the exception
and just not read that cache file back in, but recreating it from its
source. You might of course not have that option.

I have posted on ruby-core about it, but haven’t gotten much
interest/feedback. I even had a file that threw an exception on each
YAML.load. (Which I deleted some time ago)

http://thread.gmane.org/gmane.comp.lang.ruby.core/6996

No help offered there, but I wanted to show compassion… :wink:
kaspar

I’m enclosing a file that contains a Marshal’ed array. To reproduce
the failure:

gunzip enclosed file
a = Marshal.load(enclosed_file)
a == YAML.load(YAML.dump(a))

On 25/07/06, David P. [email protected] wrote:

It seems that when I YAML.dump arrays that contain long strings that
contain non-printables and sometimes UTF-8 sequences, the YAML’ed
objects can’t be read back in. Is this a known issue? If so, is
there a known work-around? Alternatively, are there any other ways to
serialize objects (JSON doesn’t work because eval() barfs on very long
strings)?

Are you using 1.8.4? I was bitten by this in Ruby 1.8.2, and actually
managed to track it down to a specific combination (when a hash key
was a string containing both 0x00 and 0x0A in a non-final position).
That specific bug seems to be fixed in 1.8.4, however.

Paul.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs