Skip to content

Commit 22af13f

Browse files
committed
Use the whole string instead of a single line for template match
1 parent a4a30a0 commit 22af13f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/addressable/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def parse_new_template_pattern(pattern, processor = nil)
10231023
end
10241024

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

spec/addressable/template_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
end
7979
end
8080

81+
describe "#to_regexp" do
82+
it "does not match the first line of multiline strings" do
83+
uri = "https://www.example.com/bar"
84+
template = Addressable::Template.new(uri)
85+
expect(template.match(uri)).not_to be_nil
86+
expect(template.match("#{uri}\ngarbage")).to be_nil
87+
end
88+
end
89+
8190
describe "Type conversion" do
8291
subject {
8392
{

0 commit comments

Comments
 (0)