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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +106 -42
- data/README.md +6 -6
- data/lib/addressable/idna/native.rb +8 -2
- data/lib/addressable/idna/pure.rb +4245 -212
- data/lib/addressable/template.rb +23 -13
- data/lib/addressable/uri.rb +178 -136
- data/lib/addressable/version.rb +2 -2
- metadata +6 -45
- data/Gemfile +0 -30
- data/Rakefile +0 -34
- data/data/unicode.data +0 -0
- data/spec/addressable/idna_spec.rb +0 -301
- data/spec/addressable/net_http_compat_spec.rb +0 -29
- data/spec/addressable/security_spec.rb +0 -58
- data/spec/addressable/template_spec.rb +0 -1468
- data/spec/addressable/uri_spec.rb +0 -6745
- data/spec/spec_helper.rb +0 -33
- data/tasks/clobber.rake +0 -4
- data/tasks/gem.rake +0 -95
- data/tasks/git.rake +0 -47
- data/tasks/metrics.rake +0 -24
- data/tasks/profile.rake +0 -72
- data/tasks/rspec.rake +0 -23
- data/tasks/yard.rake +0 -29
data/lib/addressable/template.rb
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
905
|
-
value.map! { |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[
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|