Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading/parsing regular expressions with forward slashes #715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def deserialize o
Float(@ss.tokenize(o.value))
when "!ruby/regexp"
klass = class_loader.regexp
o.value =~ /^\/(.*)\/([mixn]*)$/m
source = $1
matches = /^\/(?<string>.*)\/(?<options>[mixn]*)$/m.match(o.value)
source = matches[:string].gsub('\/', '/')
options = 0
lang = nil
$2&.each_char do |option|
matches[:options].each_char do |option|
case option
when 'x' then options |= Regexp::EXTENDED
when 'i' then options |= Regexp::IGNORECASE
Expand Down
4 changes: 4 additions & 0 deletions test/psych/test_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def test_multiline_regexp
assert_cycle(Regexp.new("foo\nbar"))
end

def test_regexp_with_slash
assert_cycle(Regexp.new('/'))
end

# [ruby-core:34969]
def test_regexp_with_n
assert_cycle(Regexp.new('',Regexp::NOENCODING))
Expand Down