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

Fix "Queries" matcher to support out-of-order query string parameters #56

Merged
merged 3 commits into from
May 27, 2014

Conversation

raphael
Copy link

@raphael raphael commented May 27, 2014

No description provided.

@raphael
Copy link
Author

raphael commented May 27, 2014

This a follow up to #55 that fixes an issue it introduced where the matches defined using ".Queries" had to be in the same order as the actual parameters in the query string. Added a test to cover this case (this test passed pre-#55 and now passes as well).

for i := 0; i < length; i = 2 {
buf.WriteString(fmt.Sprintf("%s=%s&", pairs[i], pairs[i 1]))
if r.err = r.addRegexpMatcher(fmt.Sprintf("%s=%s", pairs[i], pairs[i 1]), false, true, true); r.err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Sprintf here is probably overkill... how about just pairs[i] "=" pairs[i 1]

@raphael
Copy link
Author

raphael commented May 27, 2014

I've addressed both of your comments (thank you!).

if queryVars != nil {
for k, v := range v.query.varsN {
m.Vars[v] = queryVars[k 1]
if v.queries != nil && len(v.queries) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can actually skip this check entirely. Just leave the for _, q := range v.queries loop below. It works with nil and 0-length slices. That will remove an indent level and make this code easier to grok.

@raphael
Copy link
Author

raphael commented May 27, 2014

Thanks, addressed both of these as well.

@kisielk
Copy link
Contributor

kisielk commented May 27, 2014

Great. Reads much better now.

kisielk added a commit that referenced this pull request May 27, 2014
Fix "Queries" matcher to support out-of-order query string parameters
@kisielk kisielk merged commit 0ef595e into gorilla:master May 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants