Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created January 20, 2011 14:44
Show Gist options
  • Save igrigorik/787989 to your computer and use it in GitHub Desktop.
Save igrigorik/787989 to your computer and use it in GitHub Desktop.
diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb
index df600f7..8e3e98f 100644
--- a/lib/addressable/uri.rb
+++ b/lib/addressable/uri.rb
@@ -1420,7 +1420,7 @@ module Addressable
end
end
if hash != {} && hash.keys.all? { |key| key =~ /^\d+$/ }
- hash.sort.inject([]) do |accu, (key, value)|
+ hash.inject([]) do |accu, (key, value)|
accu << value; accu
end
else
diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb
index 670b403..97dd2ef 100644
--- a/spec/addressable/uri_spec.rb
+++ b/spec/addressable/uri_spec.rb
@@ -4281,4 +4281,12 @@ describe Addressable::URI, "when assigning path values" do
@uri.scheme = "urn"
end).should_not raise_error(Addressable::URI::InvalidURIError)
end
+
+ it "should preserve query string order" do
+ url = 'http://a.com/?'+('a'..'z').to_a.shuffle.map {|e| "#{e}=#{e}"}.join("&")
+
+ u = Addressable::URI.parse(url)
+ u.query_values = u.query_values(:notation => :flat_array)
+ u.to_s.should == url
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment