addressable 2.8.0 → 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.
@@ -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
  #
@@ -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
  #
@@ -40,6 +39,8 @@ module Addressable
40
39
  "(?>(?:[#{variable_char_class}]|%[a-fA-F0-9][a-fA-F0-9])+)"
41
40
  RESERVED =
42
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])"
43
44
  UNRESERVED =
44
45
  "(?:[#{
45
46
  Addressable::URI::CharacterClasses::UNRESERVED
@@ -158,7 +159,7 @@ module Addressable
158
159
  # the ::MatchData#[] behavior.
159
160
  #
160
161
  # @param [#to_int, nil] len
161
- # 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
162
163
  # parameter used as length.
163
164
  #
164
165
  # @return [Array, String, nil]
@@ -657,12 +658,12 @@ module Addressable
657
658
  def ordered_variable_defaults
658
659
  @ordered_variable_defaults ||= begin
659
660
  expansions, _ = parse_template_pattern(pattern)
660
- expansions.map do |capture|
661
+ expansions.flat_map do |capture|
661
662
  _, _, varlist = *capture.match(EXPRESSION)
662
663
  varlist.split(',').map do |varspec|
663
664
  varspec[VARSPEC, 1]
664
665
  end
665
- end.flatten
666
+ end
666
667
  end
667
668
  end
668
669
 
@@ -893,25 +894,24 @@ module Addressable
893
894
  # operator.
894
895
  #
895
896
  # @param [Hash, Array, String] value
896
- # Normalizes keys and values with IDNA#unicode_normalize_kc
897
+ # Normalizes unicode keys and values with String#unicode_normalize (NFC)
897
898
  #
898
899
  # @return [Hash, Array, String] The normalized values
899
900
  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
901
  # Handle unicode normalization
905
- if value.kind_of?(Array)
906
- 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) }
907
904
  elsif value.kind_of?(Hash)
908
905
  value = value.inject({}) { |acc, (k, v)|
909
- acc[Addressable::IDNA.unicode_normalize_kc(k)] =
910
- Addressable::IDNA.unicode_normalize_kc(v)
906
+ acc[normalize_value(k)] = normalize_value(v)
911
907
  acc
912
908
  }
913
909
  else
914
- 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)
915
915
  end
916
916
  value
917
917
  end
@@ -987,7 +987,8 @@ module Addressable
987
987
  _, operator, varlist = *expansion.match(EXPRESSION)
988
988
  leader = Regexp.escape(LEADERS.fetch(operator, ''))
989
989
  joiner = Regexp.escape(JOINERS.fetch(operator, ','))
990
- combined = varlist.split(',').map do |varspec|
990
+ varspecs = varlist.split(',')
991
+ combined = varspecs.map do |varspec|
991
992
  _, name, modifier = *varspec.match(VARSPEC)
992
993
 
993
994
  result = processor && processor.respond_to?(:match) ? processor.match(name) : nil
@@ -1013,7 +1014,15 @@ module Addressable
1013
1014
  "#{ UNRESERVED }*?"
1014
1015
  end
1015
1016
  if modifier == '*'
1016
- "(?<#{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}*+)?"
1017
1026
  else
1018
1027
  "(?<#{name}>#{group})?"
1019
1028
  end
@@ -1023,7 +1032,7 @@ module Addressable
1023
1032
  end
1024
1033
 
1025
1034
  # Ensure that the regular expression matches the whole URI.
1026
- regexp_string = "^#{regexp_string}$"
1035
+ regexp_string = "\\A#{regexp_string}\\z"
1027
1036
  return expansions, Regexp.new(regexp_string)
1028
1037
  end
1029
1038