Permalink
Browse files

only apply Addressable::URI patch if necessary

  • Loading branch information...
1 parent 8a1eb00 commit 61fdaef578b68dae65b06a41ca4cbfeda3516381 @mislav committed Apr 2, 2011
Showing with 14 additions and 11 deletions.
  1. +14 −11 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.