From 22af13f142d6ad1dde0095053a8c4639c960c4aa Mon Sep 17 00:00:00 2001 From: ojab Date: Thu, 2 Sep 2021 11:28:00 +0000 Subject: [PATCH] Use the whole string instead of a single line for template match --- lib/addressable/template.rb | 2 +- spec/addressable/template_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 { {