Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
only apply Addressable::URI patch if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 2, 2011
1 parent 8a1eb00 commit 61fdaef
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/faraday_stack/addressable_patch.rb
@@ -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

0 comments on commit 61fdaef

Please sign in to comment.