-
Notifications
You must be signed in to change notification settings - Fork 263
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
Ordered query_values #24
Comments
Yeah, I strongly agree. A fix will probably come in the next major release though, because my solution probably will be to change the return value to:
This format both preserves order as well as allows for handling query strings with multiple occurrences of a single key as above. But because it's a breaking change, it probably won't land until a major version release. I might make it available under a branch earlier though. |
Actually, bvandenbos just sent me a pull request that resolves this. |
Note that his patch requires you to explicitly indicate you want a :flat_array. In the future this will probably become the only format the method returns, but for now you can indicate you want it as an alternative notation. |
Awesome - thanks! |
Hmm, almost.. There are still two problems: addressable/lib/addressable/uri.rb Line 1422 in 7b13500
addressable/lib/addressable/uri.rb Line 1503 in 7b13500
Need to drop the .sort call on 1422, and remove 1503 (or make optional / conditional) url = 'http://a.com/?'+('a'..'z').to_a.shuffle.map {|e| "#{e}=#{e}"}.join("&") Above case should result in same url post query_values parse + query_parse= |
I was actually going to ask bvandenbos for some test cases to prove he'd gotten the sort order correct. But then I was lazy and didn't. Oh, well, as least my test-completeness instincts are working. I'll fix it right now. |
Bother. I just pushed a pair of test cases that cover some of the weird edge cases in some of the notation forms that addressable currently parses. Dropping the .sort call makes these tests fail in ruby 1.9.x. The |
Why is 1422 necessary? Without removing that sort, can't make this pass: |
Hmmm. Looks like the |
Actually, I added your test and the unmodified code passed just fine. Please take another look. |
Interesting! You're right, works just fine. Oi! :-) In which case, what are the odds of a point release to get this out in the wild? |
Done. |
Sweet, thanks Bob! |
Under 1.8.x, it would be nice to preserve the order of the query values, such that the query string can be reconstructed without changing the signature of the URL.
Under 1.9, ruby hashes guarantee insertion order, so.. parsing the string will result in behavior above, but this breaks under 1.8. OrderedHash under 1.8? Having this as an option, or transparent would be nice.
Ex: have a use case where we need to parse the QS, delete a few variables, and re-assemble it. After re-assembling it, we need to guarantee that we'll end up with same order of parameters between different processes.
The text was updated successfully, but these errors were encountered: