# Syck dies on multiline regex

**URL:** <https://www.ruby-forum.com/t/syck-dies-on-multiline-regex/208269>\
**Category:** Ruby\
**Created:** [June 13, 2011, 9:34pm UTC](https://www.ruby-forum.com/t/syck-dies-on-multiline-regex/208269 "2011-06-13T21:34:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 13, 2011, 9:34pm UTC](https://www.ruby-forum.com/t/syck-dies-on-multiline-regex/208269/1 "2011-06-13T21:34:47Z")

</div>

require ‘yaml’  
[YAML, Marshal].each do |serializer|  
[/ab/x, /a  
b/x].each do |regex|  
begin  
serializer.load(serializer.dump regex)  
rescue  
p $!  
end  
end  
end

# \>\> #\<Syck::TypeError: Invalid Regular expression: "/a\n

b/x"\>

This, in tandem with a few other things, cost me about four hours today  
(and  
made me reconsider my decision to become a nonsmoker -.-).

Is this a bug? If so, where should I report it?

---

<div class="post-metadata">

**Author:** ![jcain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3d9bf3/32.png) [@jcain](https://www.ruby-forum.com/u/jcain)\
**Post date:** [June 13, 2011, 10:37pm UTC](https://www.ruby-forum.com/t/syck-dies-on-multiline-regex/208269/2 "2011-06-13T22:37:14Z")

</div>

On Jun 13, 2011, at 12:34 , Josh C. wrote:

> end
> 
> # \>\> #\<Syck::TypeError: Invalid Regular expression: “/a\n b/x”\>
> 
> This, in tandem with a few other things, cost me about four hours today (and  
> made me reconsider my decision to become a nonsmoker -.-).
> 
> Is this a bug? If so, where should I report it?

It is probably a bug. It _probably_ won’t ever get fixed as nobody  
really maintains syck anymore (tho if you come up with a patch, that’d  
certainly help). Try psych if it is possible:

6371 % ruby19 -rpsych -ryaml -e ‘p YAML.dump /a  
b/x’  
“— !ruby/regexp "/a\n b/x"\n”

---

<div class="post-metadata">

**Author:** ![jcain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3d9bf3/32.png) [@jcain](https://www.ruby-forum.com/u/jcain)\
**Post date:** [June 14, 2011, 2:50am UTC](https://www.ruby-forum.com/t/syck-dies-on-multiline-regex/208269/3 "2011-06-14T02:50:13Z")

</div>

On Mon, Jun 13, 2011 at 3:34 PM, Josh C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> # \>\> #\<Syck::TypeError: Invalid Regular expression: “/a\n b/x”\>
> 
> Is this a bug?

Probably.

> If so, where should I report it?

> **[Ruby Issue Tracking System](https://redmine.ruby-lang.org/)**
>
> Redmine

Though, as noted, syck is not maintained and psych appears to be the  
future.

I have no idea what else I broke :-), but this change runs your sample:

$ ruby -v -S irb  
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

> > require ‘yaml’  
> > =\> true  
> > [YAML, Marshal].each do |serializer|  
> > ?\> [/ab/x, /a  
> > b/x].each do |regex|  
> > ?\> begin  
> > ?\> serializer.load(serializer.dump regex)  
> > rescue  
> > p $!  
> > end  
> > end  
> > end  
> > =\> [YAML, Marshal]

* * *

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml/rubytypes.rb.orig  
2011-06-13  
20:45:05.000000000 -0400  
+++  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml/rubytypes.rb  
2011-06-13  
20:43:20.000000000 -0400  
@@ -253,7 +253,7 @@  
class Regexp  
yaml\_as “tag:ruby.yaml.org,2002:regexp”  
def Regexp.yaml\_new( klass, tag, val )

- 

```
   if String === val and val =~ /^\/(.*)\/([mix]*)$/

```

- 

```
   if String === val and val =~ /^\/(.*)\/([mix]*)$/m
       val = { 'regexp' => $1, 'mods' => $2 }
   end
   if Hash === val

```
