Giter Site home page Giter Site logo

Comments (13)

sporkmonger avatar sporkmonger commented on July 21, 2024

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:

[['a', '1'], ['a', '2']]

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.

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

Actually, bvandenbos just sent me a pull request that resolves this.

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

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.

from addressable.

igrigorik avatar igrigorik commented on July 21, 2024

Awesome - thanks!

from addressable.

igrigorik avatar igrigorik commented on July 21, 2024

Hmm, almost.. There are still two problems:

hash.sort.inject([]) do |accu, (key, value)|

new_query_values.sort! # Useful default for OAuth and caching

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=

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

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.

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

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 .sort call on line 1422 is necessary. However I moved the sorting code on line 1503 up into the non-Array input block, so it will only sort if you give it a Hash input. Admittedly, this might be a bit aggressive in 1.9.x where order is preserved in Hash values, but you'll always have the Array option available if it matters. I'm not concerned about the occasional instance where someone has to do an extra .to_a call on their 1.9.x Hash to ensure order is preserved.

from addressable.

igrigorik avatar igrigorik commented on July 21, 2024

Why is 1422 necessary? Without removing that sort, can't make this pass:

https://gist.github.com/787989

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

Hmmm. Looks like the .sort call is having an unintentional side-effect. The intent was to sort Hash values, not Array values. For instance: ?a[1]=one&a[0]=zero should parse to {'a' => ['zero', 'one']}.

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

Actually, I added your test and the unmodified code passed just fine. Please take another look.

from addressable.

igrigorik avatar igrigorik commented on July 21, 2024

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?

from addressable.

sporkmonger avatar sporkmonger commented on July 21, 2024

Done.

from addressable.

igrigorik avatar igrigorik commented on July 21, 2024

Sweet, thanks Bob!

from addressable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.