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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +94 -39
- data/Gemfile +5 -2
- data/Rakefile +11 -8
- data/addressable.gemspec +9 -18
- data/lib/addressable/idna/native.rb +8 -3
- data/lib/addressable/idna/pure.rb +10 -183
- data/lib/addressable/idna.rb +0 -1
- data/lib/addressable/template.rb +13 -15
- data/lib/addressable/uri.rb +231 -185
- data/lib/addressable/version.rb +1 -2
- data/spec/addressable/idna_spec.rb +6 -6
- data/spec/addressable/net_http_compat_spec.rb +0 -1
- data/spec/addressable/security_spec.rb +0 -1
- data/spec/addressable/template_spec.rb +69 -265
- data/spec/addressable/uri_spec.rb +176 -1
- data/tasks/gem.rake +7 -4
- metadata +8 -7
data/lib/addressable/template.rb
CHANGED
@@ -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
|
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.
|
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
|
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
|
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.
|
906
|
-
value.map! { |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[
|
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 =
|
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 = "
|
1024
|
+
regexp_string = "\\A#{regexp_string}\\z"
|
1027
1025
|
return expansions, Regexp.new(regexp_string)
|
1028
1026
|
end
|
1029
1027
|
|