diff --git a/lib/addressable/template.rb b/lib/addressable/template.rb index 232595c1..9e8174bf 100644 --- a/lib/addressable/template.rb +++ b/lib/addressable/template.rb @@ -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 diff --git a/spec/addressable/template_spec.rb b/spec/addressable/template_spec.rb index feaa9bde..f7b0994c 100644 --- a/spec/addressable/template_spec.rb +++ b/spec/addressable/template_spec.rb @@ -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 { {