addressable 2.8.1 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,8 @@ module Addressable
39
39
  "(?>(?:[#{variable_char_class}]|%[a-fA-F0-9][a-fA-F0-9])+)"
40
40
  RESERVED =
41
41
  "(?:[#{anything}]|%[a-fA-F0-9][a-fA-F0-9])"
42
+ RESERVED_NO_COMMA =
43
+ "(?:[#{anything.delete(',')}]|%[a-fA-F0-9][a-fA-F0-9])"
42
44
  UNRESERVED =
43
45
  "(?:[#{
44
46
  Addressable::URI::CharacterClasses::UNRESERVED
@@ -157,7 +159,7 @@ module Addressable
157
159
  # the ::MatchData#[] behavior.
158
160
  #
159
161
  # @param [#to_int, nil] len
160
- # If provided, an array of values will be returend with the given
162
+ # If provided, an array of values will be returned with the given
161
163
  # parameter used as length.
162
164
  #
163
165
  # @return [Array, String, nil]
@@ -892,25 +894,24 @@ module Addressable
892
894
  # operator.
893
895
  #
894
896
  # @param [Hash, Array, String] value
895
- # Normalizes keys and values with IDNA#unicode_normalize_kc
897
+ # Normalizes unicode keys and values with String#unicode_normalize (NFC)
896
898
  #
897
899
  # @return [Hash, Array, String] The normalized values
898
900
  def normalize_value(value)
899
- unless value.is_a?(Hash)
900
- value = value.respond_to?(:to_ary) ? value.to_ary : value.to_str
901
- end
902
-
903
901
  # Handle unicode normalization
904
- if value.kind_of?(Array)
905
- value.map! { |val| Addressable::IDNA.unicode_normalize_kc(val) }
902
+ if value.respond_to?(:to_ary)
903
+ value.to_ary.map! { |val| normalize_value(val) }
906
904
  elsif value.kind_of?(Hash)
907
905
  value = value.inject({}) { |acc, (k, v)|
908
- acc[Addressable::IDNA.unicode_normalize_kc(k)] =
909
- Addressable::IDNA.unicode_normalize_kc(v)
906
+ acc[normalize_value(k)] = normalize_value(v)
910
907
  acc
911
908
  }
912
909
  else
913
- value = Addressable::IDNA.unicode_normalize_kc(value)
910
+ value = value.to_s if !value.kind_of?(String)
911
+ if value.encoding != Encoding::UTF_8
912
+ value = value.dup.force_encoding(Encoding::UTF_8)
913
+ end
914
+ value = value.unicode_normalize(:nfc)
914
915
  end
915
916
  value
916
917
  end
@@ -986,7 +987,8 @@ module Addressable
986
987
  _, operator, varlist = *expansion.match(EXPRESSION)
987
988
  leader = Regexp.escape(LEADERS.fetch(operator, ''))
988
989
  joiner = Regexp.escape(JOINERS.fetch(operator, ','))
989
- combined = varlist.split(',').map do |varspec|
990
+ varspecs = varlist.split(',')
991
+ combined = varspecs.map do |varspec|
990
992
  _, name, modifier = *varspec.match(VARSPEC)
991
993
 
992
994
  result = processor && processor.respond_to?(:match) ? processor.match(name) : nil
@@ -1012,7 +1014,15 @@ module Addressable
1012
1014
  "#{ UNRESERVED }*?"
1013
1015
  end
1014
1016
  if modifier == '*'
1015
- "(?<#{name}>#{group}(?:#{joiner}?#{group})*)?"
1017
+ seg = case operator
1018
+ when '+', '#' then "#{RESERVED_NO_COMMA}*+"
1019
+ else group
1020
+ end
1021
+ joiner_pattern = operator.nil? ? joiner : "#{joiner}?"
1022
+ "(?<#{name}>#{seg}(?:#{joiner_pattern}#{seg})*)?"
1023
+ elsif varspecs.size > 1 && (operator == '+' || operator == '#') &&
1024
+ varspec != varspecs.last
1025
+ "(?<#{name}>#{RESERVED_NO_COMMA}*+)?"
1016
1026
  else
1017
1027
  "(?<#{name}>#{group})?"
1018
1028
  end