diff --git a/lib/addressable/template.rb b/lib/addressable/template.rb index 398af17c..90be672d 100644 --- a/lib/addressable/template.rb +++ b/lib/addressable/template.rb @@ -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 diff --git a/spec/addressable/template_spec.rb b/spec/addressable/template_spec.rb index d47589ab..bba4adef 100644 --- a/spec/addressable/template_spec.rb +++ b/spec/addressable/template_spec.rb @@ -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 { {