Skip to content

Commit 7d03b91

Browse files
authored
Merge pull request #715 from mamhoff/fix-parse-reload-regexps
Fix loading/parsing regular expressions with forward slashes
2 parents bb63f91 + f4dd8da commit 7d03b91

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/psych/visitors/to_ruby.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ def deserialize o
9696
Float(@ss.tokenize(o.value))
9797
when "!ruby/regexp"
9898
klass = class_loader.regexp
99-
o.value =~ /^\/(.*)\/([mixn]*)$/m
100-
source = $1
99+
matches = /^\/(?<string>.*)\/(?<options>[mixn]*)$/m.match(o.value)
100+
source = matches[:string].gsub('\/', '/')
101101
options = 0
102102
lang = nil
103-
$2&.each_char do |option|
103+
matches[:options].each_char do |option|
104104
case option
105105
when 'x' then options |= Regexp::EXTENDED
106106
when 'i' then options |= Regexp::IGNORECASE

test/psych/test_yaml.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def test_multiline_regexp
3535
assert_cycle(Regexp.new("foo\nbar"))
3636
end
3737

38+
def test_regexp_with_slash
39+
assert_cycle(Regexp.new('/'))
40+
end
41+
3842
# [ruby-core:34969]
3943
def test_regexp_with_n
4044
assert_cycle(Regexp.new('',Regexp::NOENCODING))

0 commit comments

Comments
 (0)