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

Sorting query parameters undesireable #245

Merged

Conversation

Billiam
Copy link
Contributor

@Billiam Billiam commented Oct 20, 2013

Some services return results based on the query parameter order (ex: mapquest's batch query api), and sorting may break input/output mapping unexpectedly.

Patch removes the sort call from the NON_RAILS_QUERY_STRING_NORMALIZER proc, and updates spec expectations accordingly.

[Edit]
Patch sorts query parameters by key in the NON_RAILS_QUERY_STRING_NORMALIZER proc, prior to processing. This adds some consistency across ruby versions during the actual processing, and removes the value sorting which affected query array values

Updates the array value test to check for maintained query values, and sorting of keys.

@jnunemaker
Copy link
Owner

Query string order should never matter, right? So this should not affect anyone else? The one way it will is stubbing requests in specs, which is probably why it was added. Anyone have any thoughts on this either way?

@Billiam
Copy link
Contributor Author

Billiam commented Oct 21, 2013

Query string order should never matter, right?

Unfortunately, whether it matters will depend on the receiving end. I ran into this issue working with an api (mapquest batch geocoding), where the incoming argument order determines the output result order, and the parameter sort caused mismatching.

It looks like the PR build failed for ree 2012.02 specifically, which I've been unable to build locally. I'm not sure whether there's some implicit argument sorting going on there...

@Billiam
Copy link
Contributor Author

Billiam commented Oct 21, 2013

After some testing, the sorted/unsorted behavior of Array() in different 1.8.7 versions is pretty varied.

A better fix, here, might just be to sort before flattening rather than after, which would retain the order of array hash values (while still sorting other params). The original tests would pass, and a test could be added to ensure array values are not sorted. Thoughts?

@jnunemaker
Copy link
Owner

That makes sense I think.

 - Query parameter order in specs to use sorted values again
 - Adding test for maintained array value order
 - Updating test to include mix of array and non-array values for sort.
jnunemaker pushed a commit that referenced this pull request Jan 4, 2014
@jnunemaker jnunemaker merged commit 7c1a19e into jnunemaker:master Jan 4, 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