# YAML Broken?

**URL:** <https://www.ruby-forum.com/t/yaml-broken/99864>\
**Category:** Ruby\
**Created:** [July 25, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/yaml-broken/99864 "2006-07-25T23:42:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 25, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/yaml-broken/99864/1 "2006-07-25T23:42:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 25, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/yaml-broken/99864/2 "2006-07-25T23:58:50Z")

</div>

David P. wrote:

> David

There’s always Marshal.

[http://ruby-doc.org/core/classes/Marshal.html](http://ruby-doc.org/core/classes/Marshal.html)

-Justin

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 12:05am UTC](https://www.ruby-forum.com/t/yaml-broken/99864/3 "2006-07-26T00:05:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 1:55am UTC](https://www.ruby-forum.com/t/yaml-broken/99864/4 "2006-07-26T01:55:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 12:14am UTC](https://www.ruby-forum.com/t/yaml-broken/99864/5 "2006-07-26T00:14:14Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 8:27am UTC](https://www.ruby-forum.com/t/yaml-broken/99864/6 "2006-07-26T08:27:01Z")

</div>

> 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](http://thread.gmane.org/gmane.comp.lang.ruby.core/6996)

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

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/yaml-broken/99864/7 "2006-07-26T18:00:36Z")

</div>

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))

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [July 26, 2006, 10:19am UTC](https://www.ruby-forum.com/t/yaml-broken/99864/8 "2006-07-26T10:19:54Z")

</div>

On 25/07/06, David P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
