Syck dies on multiline regex

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?

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”

On Mon, Jun 13, 2011 at 3:34 PM, Josh C. [email protected]
wrote:

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

Is this a bug?

Probably.

If so, where should I report it?

http://redmine.ruby-lang.org/

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

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