Created
February 17, 2011 22:51
-
-
Save mislav/832913 to your computer and use it in GitHub Desktop.
Fixes comparing instances of Addressable::URI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'addressable/uri' | |
# feature-detect the bug | |
unless Addressable::URI.parse('/?a=1&b=2') === '/?b=2&a=1' | |
# fix `normalized_query` by sorting query key-value pairs | |
# (rejected: https://github.com/sporkmonger/addressable/issues/28) | |
class Addressable::URI | |
class << self | |
alias normalize_component_without_query_fix normalize_component | |
def normalize_component(component, character_class = CharacterClasses::RESERVED + CharacterClasses::UNRESERVED) | |
normalized = normalize_component_without_query_fix(component, character_class) | |
if character_class == Addressable::URI::CharacterClasses::QUERY | |
pairs = normalized.split('&').sort_by { |pair| pair[0, pair.index('=') || pair.length] } | |
normalized = pairs.join('&') | |
end | |
normalized | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment