Skip to content

Commit

Permalink
Merge pull request #2222 from natalie-lang/regexp-escape
Browse files Browse the repository at this point in the history
Fix Regexp.escape/quote not escaping dollar signs
  • Loading branch information
herwinw committed Sep 18, 2024
2 parents 905f767 + 5f8f215 commit 1ffc88c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions spec/core/regexp/shared/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def obj.to_str() [] end
end

it "raises a RegexpError when passed an incorrect regexp" do
NATFIXME 'Update error message', exception: SpecFailedException, message: /but the message was/ do
-> { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError, Regexp.new(Regexp.escape("premature end of char-class: /^[$/")))
end
-> { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError, Regexp.new(Regexp.escape("premature end of char-class: /^[$/")))
end

it "does not set Regexp options if only given one argument" do
Expand Down
1 change: 1 addition & 0 deletions src/regexp_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Value RegexpObject::quote(Env *env, Value string) {
case '.':
case '+':
case '^':
case '$':
case '[':
case ']':
case '(':
Expand Down
6 changes: 6 additions & 0 deletions test/natalie/regexp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
end
end

describe '.escape and .quote' do
it 'escapes special characters' do
Regexp.escape('$').should == '\$'
end
end

describe '#==' do
it 'returns true if the regexp source is the same' do
/foo/.should == /foo/
Expand Down

0 comments on commit 1ffc88c

Please sign in to comment.