This repository has been archived by the owner on Oct 20, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only apply Addressable::URI patch if necessary
- Loading branch information
Showing
1 changed file
with
14 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
require 'addressable/uri' | ||
|
||
# fix `normalized_query` by sorting query key-value pairs | ||
# (rejected: https://github.com/sporkmonger/addressable/issues/28) | ||
class Addressable::URI | ||
class << self | ||
alias old_normalize_component normalize_component | ||
# 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 = old_normalize_component(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('&') | ||
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 | ||
normalized | ||
end | ||
end | ||
end |