Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the whole string instead of a single line for template match #431

Merged
merged 2 commits into from Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/addressable/template.rb
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions spec/addressable/template_spec.rb
Expand Up @@ -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"

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames

This string, which is used as a regular expression [here](1), has an unescaped '.' before 'example.com/bar', so it might match more hosts than expected. This string, which is used as a regular expression [here](2), has an unescaped '.' before 'example.com/bar', so it might match more hosts than expected.
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 {
{
Expand Down