Skip to content

Commit 99810af

Browse files
authored
Merge pull request #431 from ojab/ct-_do_not_parse_multiline_strings
Use the whole string instead of a single line for template match
2 parents 7ecf751 + 7ce0f48 commit 99810af

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/addressable/template.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ def parse_new_template_pattern(pattern, processor = nil)
10221022
end
10231023

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

spec/addressable/template_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@
7777
end
7878
end
7979

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

0 commit comments

Comments
 (0)