addressable 2.8.0 → 2.8.7

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.
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # encoding:utf-8
4
3
  #--
5
4
  # Copyright (C) Bob Aman
6
5
  #
@@ -158,7 +157,7 @@ module Addressable
158
157
  # the ::MatchData#[] behavior.
159
158
  #
160
159
  # @param [#to_int, nil] len
161
- # If provided, an array of values will be returend with the given
160
+ # If provided, an array of values will be returned with the given
162
161
  # parameter used as length.
163
162
  #
164
163
  # @return [Array, String, nil]
@@ -657,12 +656,12 @@ module Addressable
657
656
  def ordered_variable_defaults
658
657
  @ordered_variable_defaults ||= begin
659
658
  expansions, _ = parse_template_pattern(pattern)
660
- expansions.map do |capture|
659
+ expansions.flat_map do |capture|
661
660
  _, _, varlist = *capture.match(EXPRESSION)
662
661
  varlist.split(',').map do |varspec|
663
662
  varspec[VARSPEC, 1]
664
663
  end
665
- end.flatten
664
+ end
666
665
  end
667
666
  end
668
667
 
@@ -893,25 +892,24 @@ module Addressable
893
892
  # operator.
894
893
  #
895
894
  # @param [Hash, Array, String] value
896
- # Normalizes keys and values with IDNA#unicode_normalize_kc
895
+ # Normalizes unicode keys and values with String#unicode_normalize (NFC)
897
896
  #
898
897
  # @return [Hash, Array, String] The normalized values
899
898
  def normalize_value(value)
900
- unless value.is_a?(Hash)
901
- value = value.respond_to?(:to_ary) ? value.to_ary : value.to_str
902
- end
903
-
904
899
  # Handle unicode normalization
905
- if value.kind_of?(Array)
906
- value.map! { |val| Addressable::IDNA.unicode_normalize_kc(val) }
900
+ if value.respond_to?(:to_ary)
901
+ value.to_ary.map! { |val| normalize_value(val) }
907
902
  elsif value.kind_of?(Hash)
908
903
  value = value.inject({}) { |acc, (k, v)|
909
- acc[Addressable::IDNA.unicode_normalize_kc(k)] =
910
- Addressable::IDNA.unicode_normalize_kc(v)
904
+ acc[normalize_value(k)] = normalize_value(v)
911
905
  acc
912
906
  }
913
907
  else
914
- value = Addressable::IDNA.unicode_normalize_kc(value)
908
+ value = value.to_s if !value.kind_of?(String)
909
+ if value.encoding != Encoding::UTF_8
910
+ value = value.dup.force_encoding(Encoding::UTF_8)
911
+ end
912
+ value = value.unicode_normalize(:nfc)
915
913
  end
916
914
  value
917
915
  end
@@ -1023,7 +1021,7 @@ module Addressable
1023
1021
  end
1024
1022
 
1025
1023
  # Ensure that the regular expression matches the whole URI.
1026
- regexp_string = "^#{regexp_string}$"
1024
+ regexp_string = "\\A#{regexp_string}\\z"
1027
1025
  return expansions, Regexp.new(regexp_string)
1028
1026
  end
1029
1027