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

Extraction inconsistencies when some keys match an extraction #193

Open
jnicklas opened this issue Apr 29, 2015 · 1 comment
Open

Extraction inconsistencies when some keys match an extraction #193

jnicklas opened this issue Apr 29, 2015 · 1 comment

Comments

@jnicklas
Copy link

Suppose we have a template like this:

template = Addressable::Template.new('/path{?page,per_page}')

If we call extract with a URL which contains a query parameter that is not included in the list of allowed query parameters, the behaviour depends on whether the allowed parameters are provided or not.

template.extract('/path?page=2&foo=bar') # => {"page"=>"2", "per_page"=>nil, "foo"=>"bar"}
template.extract('/path?page=2&per_page=10&foo=bar') # => nil
template.extract('/path?foo=bar') # => {"page"=>nil, "foo"=>"bar", "per_page"=>nil}

In any of the above extractions, foo should not be present in the result.

It gets even stranger when we add a splat into the mix:

template = Addressable::Template.new('/path{?page,other*}')

This results in extractions like this:

template.extract('/path?page=2') # => {"page"=>"2", "other"=>nil}
template.extract('/path?page=2&foo=bar') # => {"page"=>"2", "other"=>{"foo"=>"bar"}}
template.extract('/path?quox=baz&page=2') # => {"page"=>nil, "quox"=>"baz", "other"=>{"page"=>"2"}}
template.extract('/path?quox=baz&page=2&foo=bar') # => {"page"=>nil, "quox"=>"baz", "other"=>{"page"=>"2", "foo"=>"bar"}}

Look particularly at the third and fourth line, it seems like such a match should either be rejected outright or should result in page being set correctly.

@jnicklas
Copy link
Author

It's also inconsistent between matching a query parameter, which makes the extraction match any query parameter, and not matching a query parameter in which case we can't provide any query parameters at all.

Addressable::Template.new('/path{?page}').extract('/path?foo=bar') # => {"page"=>nil, "foo"=>"bar"}
Addressable::Template.new('/path').extract('/path?foo=bar') # => nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants