Skip to content

Commit

Permalink
Merge pull request #431 from ojab/ct-_do_not_parse_multiline_strings
Browse files Browse the repository at this point in the history
Use the whole string instead of a single line for template match
  • Loading branch information
sporkmonger authored Jul 30, 2022
2 parents 7ecf751 + 7ce0f48 commit 99810af
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
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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 99810af

Please # to comment.