Skip to content

Commit

Permalink
Use the whole string instead of a single line for template match
Browse files Browse the repository at this point in the history
  • Loading branch information
ojab committed Sep 2, 2021
1 parent a4a30a0 commit a2f32c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/addressable/template.rb
Expand Up @@ -1023,7 +1023,7 @@ def parse_new_template_pattern(pattern, processor = nil)
end

# Ensure that the regular expression matches the whole URI.
regexp_string = "^#{regexp_string}$"
regexp_string = "\\A#{regexp_string}\\z"
return expansions, Regexp.new(regexp_string)
end

Expand Down
9 changes: 9 additions & 0 deletions spec/addressable/template_spec.rb
Expand Up @@ -78,6 +78,15 @@
end
end

describe "#to_regexp" do
it 'does not match the first line of multiline strings' do
uri = 'https://www.example.com/bar'
template = Addressable::Template.new(uri)
expect(template.match(uri)).not_to be_nil
expect(template.match("#{uri}\ngarbage")).to be_nil
end
end

describe "Type conversion" do
subject {
{
Expand Down

0 comments on commit a2f32c7

Please sign in to comment.