Skip to content

Instantly share code, notes, and snippets.

@sporkmonger
Last active December 20, 2015 12:58
Show Gist options
  • Save sporkmonger/6134614 to your computer and use it in GitHub Desktop.
Save sporkmonger/6134614 to your computer and use it in GitHub Desktop.
diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb
index a13601f..f297244 100644
--- a/lib/addressable/uri.rb
+++ b/lib/addressable/uri.rb
@@ -1449,21 +1449,16 @@ module Addressable
# The query component for this URI, normalized.
#
# @return [String] The query component, normalized.
- def normalized_query
- self.query && @normalized_query ||= (begin
- modified_query_class = Addressable::URI::CharacterClasses::QUERY
- # Make sure possible key-value pair delimiters are escaped.
- modified_query_class = modified_query_class.sub("\\&", "")
- modified_query_class = modified_query_class.sub("\\;", "")
- component = (self.query.split("&", -1).map do |pair|
- Addressable::URI.normalize_component(
- pair,
- modified_query_class,
- "+"
- )
- end).join("&")
- component == "" ? nil : component
- end)
+ def normalized_query(*flags)
+ modified_query_class = Addressable::URI::CharacterClasses::QUERY.dup
+ # Make sure possible key-value pair delimiters are escaped.
+ modified_query_class.sub!("\\&", "").sub!("\\;", "")
+ pairs = (self.query || "").split("&", -1)
+ pairs.sort! if flags.include?(:sorted)
+ component = (pairs.map do |pair|
+ Addressable::URI.normalize_component(pair, modified_query_class, "+")
+ end).join("&")
+ component == "" ? nil : component
end
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment