addressable 2.8.3 → 2.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 840ea726b6e004eb1de70a362907bd86cecb0e964f0ed149252a2302c0048756
4
- data.tar.gz: 6590611472bebb1e7c783f5f8e2e9c6c1fb5266017bba33a1cb34c4ce6c10bcb
3
+ metadata.gz: 5b7d4ea3b683b3b7c719ae54919505e8e98823b39e54cd68d3579319b61d9824
4
+ data.tar.gz: d09b61eba34544826aec64909b848b53549ae64059e09cc5f462991a59fd2465
5
5
  SHA512:
6
- metadata.gz: fd7ec4ba810a0c160df99622e4198687cde10124a28a65b1193d2a7760d6660b3518028f06a686648fb0b57881d8f68f30a61162f100d4974f2ffc612373dcb6
7
- data.tar.gz: 5be14161f50be1dc3d766ee69027740f667672ee0b22ee2dd727bace6c0c6f5999de641bdfc516dbbbf3fb9d458be2499454e6e3d12b572cb923eba0f47e735b
6
+ metadata.gz: 37927e878581e256a98ac619723a90f7b7a2d5b655ef613872a4f963ffdccabc6f0b761b65673fc6929509b0f783b48460b2643ac33c2d076bc5234e4126573b
7
+ data.tar.gz: 3afd1d272e41f97959bc8b34188b8d9fc419fcc01af9ea8a955d3ee2e6f57e3417d5ec6c58378e6b29fedb15e948ace7c080cd2c3739d6e24a4dd04eb3fa3f70
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # Addressable 2.8.5
2
+ - Fix thread safety issue with encoding tables ([#515])
3
+ - Define URI::NONE as a module to avoid serialization issues ([#509])
4
+ - Fix YAML serialization ([#508])
5
+
6
+ [#508]: https://github.com/sporkmonger/addressable/pull/508
7
+ [#509]: https://github.com/sporkmonger/addressable/pull/509
8
+ [#515]: https://github.com/sporkmonger/addressable/pull/515
9
+
10
+ # Addressable 2.8.4
11
+ - Restore `Addressable::IDNA.unicode_normalize_kc` as a deprecated method ([#504])
12
+
13
+ [#504]: https://github.com/sporkmonger/addressable/pull/504
14
+
1
15
  # Addressable 2.8.3
2
16
  - Fix template expand level 2 hash support for non-string objects ([#499], [#498])
3
17
 
data/Rakefile CHANGED
@@ -20,12 +20,17 @@ additionally provides extensive support for IRIs and URI templates.
20
20
  TEXT
21
21
 
22
22
  PKG_FILES = FileList[
23
- "lib/**/*", "spec/**/*", "vendor/**/*", "data/**/*",
24
- "tasks/**/*",
25
- "[A-Z]*", "Rakefile"
26
- ].exclude(/pkg/).exclude(/database\.yml/).
27
- exclude(/Gemfile\.lock/).exclude(/[_\.]git$/).
28
- exclude(/coverage/)
23
+ "data/**/*",
24
+ "lib/**/*.rb",
25
+ "spec/**/*.rb",
26
+ "tasks/**/*.rake",
27
+ "addressable.gemspec",
28
+ "CHANGELOG.md",
29
+ "Gemfile",
30
+ "LICENSE.txt",
31
+ "README.md",
32
+ "Rakefile",
33
+ ]
29
34
 
30
35
  task :default => "spec"
31
36
 
data/addressable.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: addressable 2.8.3 ruby lib
2
+ # stub: addressable 2.8.5 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "addressable".freeze
6
- s.version = "2.8.3"
6
+ s.version = "2.8.5"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.metadata = { "changelog_uri" => "https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md" } if s.respond_to? :metadata=
10
10
  s.require_paths = ["lib".freeze]
11
11
  s.authors = ["Bob Aman".freeze]
12
- s.date = "2023-04-04"
12
+ s.date = "2023-08-03"
13
13
  s.description = "Addressable is an alternative implementation to the URI implementation that is\npart of Ruby's standard library. It is flexible, offers heuristic parsing, and\nadditionally provides extensive support for IRIs and URI templates.\n".freeze
14
14
  s.email = "bob@sporkmonger.com".freeze
15
15
  s.extra_rdoc_files = ["README.md".freeze]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.licenses = ["Apache-2.0".freeze]
19
19
  s.rdoc_options = ["--main".freeze, "README.md".freeze]
20
20
  s.required_ruby_version = Gem::Requirement.new(">= 2.2".freeze)
21
- s.rubygems_version = "3.4.8".freeze
21
+ s.rubygems_version = "3.4.18".freeze
22
22
  s.summary = "URI Implementation".freeze
23
23
 
24
24
  s.specification_version = 4
@@ -29,6 +29,16 @@ module Addressable
29
29
  IDN::Punycode.decode(value.to_s)
30
30
  end
31
31
 
32
+ class << self
33
+ # @deprecated Use {String#unicode_normalize(:nfkc)} instead
34
+ def unicode_normalize_kc(value)
35
+ value.to_s.unicode_normalize(:nfkc)
36
+ end
37
+
38
+ extend Gem::Deprecate
39
+ deprecate :unicode_normalize_kc, "String#unicode_normalize(:nfkc)", 2023, 4
40
+ end
41
+
32
42
  def self.to_ascii(value)
33
43
  value.to_s.split('.', -1).map do |segment|
34
44
  if segment.size > 0 && segment.size < 64
@@ -112,6 +112,16 @@ module Addressable
112
112
  output
113
113
  end
114
114
 
115
+ class << self
116
+ # @deprecated Use {String#unicode_normalize(:nfkc)} instead
117
+ def unicode_normalize_kc(value)
118
+ value.to_s.unicode_normalize(:nfkc)
119
+ end
120
+
121
+ extend Gem::Deprecate
122
+ deprecate :unicode_normalize_kc, "String#unicode_normalize(:nfkc)", 2023, 4
123
+ end
124
+
115
125
  ##
116
126
  # Unicode aware downcase method.
117
127
  #
@@ -344,17 +344,13 @@ module Addressable
344
344
  ##
345
345
  # Tables used to optimize encoding operations in `self.encode_component`
346
346
  # and `self.normalize_component`
347
- SEQUENCE_ENCODING_TABLE = Hash.new do |hash, sequence|
348
- hash[sequence] = sequence.unpack("C*").map do |c|
349
- format("%02x", c)
350
- end.join
351
- end
347
+ SEQUENCE_ENCODING_TABLE = (0..255).map do |byte|
348
+ format("%02x", byte).freeze
349
+ end.freeze
352
350
 
353
- SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE = Hash.new do |hash, sequence|
354
- hash[sequence] = sequence.unpack("C*").map do |c|
355
- format("%%%02X", c)
356
- end.join
357
- end
351
+ SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE = (0..255).map do |byte|
352
+ format("%%%02X", byte).freeze
353
+ end.freeze
358
354
 
359
355
  ##
360
356
  # Percent encodes a URI component.
@@ -421,16 +417,17 @@ module Addressable
421
417
  component = component.dup
422
418
  component.force_encoding(Encoding::ASCII_8BIT)
423
419
  # Avoiding gsub! because there are edge cases with frozen strings
424
- component = component.gsub(character_class) do |sequence|
425
- SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE[sequence]
420
+ component = component.gsub(character_class) do |char|
421
+ SEQUENCE_UPCASED_PERCENT_ENCODING_TABLE[char.ord]
426
422
  end
427
423
  if upcase_encoded.length > 0
428
- upcase_encoded_chars = upcase_encoded.chars.map do |char|
429
- SEQUENCE_ENCODING_TABLE[char]
424
+ upcase_encoded_chars = upcase_encoded.bytes.map do |byte|
425
+ SEQUENCE_ENCODING_TABLE[byte]
430
426
  end
431
427
  component = component.gsub(/%(#{upcase_encoded_chars.join('|')})/,
432
428
  &:upcase)
433
429
  end
430
+
434
431
  return component
435
432
  end
436
433
 
@@ -560,10 +557,9 @@ module Addressable
560
557
  leave_re = if leave_encoded.length > 0
561
558
  character_class = "#{character_class}%" unless character_class.include?('%')
562
559
 
563
- "|%(?!#{leave_encoded.chars.flat_map do |char|
564
- seq = SEQUENCE_ENCODING_TABLE[char]
565
- [seq.upcase, seq.downcase]
566
- end.join('|')})"
560
+ bytes = leave_encoded.bytes
561
+ leave_encoded_pattern = bytes.map { |b| SEQUENCE_ENCODING_TABLE[b] }.join('|')
562
+ "|%(?!#{leave_encoded_pattern}|#{leave_encoded_pattern.upcase})"
567
563
  end
568
564
 
569
565
  character_class = if leave_re
@@ -2396,6 +2392,25 @@ module Addressable
2396
2392
  @validation_deferred = false
2397
2393
  end
2398
2394
 
2395
+ def encode_with(coder)
2396
+ instance_variables.each do |ivar|
2397
+ value = instance_variable_get(ivar)
2398
+ if value != NONE
2399
+ key = ivar.to_s.slice(1..-1)
2400
+ coder[key] = value
2401
+ end
2402
+ end
2403
+ nil
2404
+ end
2405
+
2406
+ def init_with(coder)
2407
+ reset_ivs
2408
+ coder.map.each do |key, value|
2409
+ instance_variable_set("@#{key}", value)
2410
+ end
2411
+ nil
2412
+ end
2413
+
2399
2414
  protected
2400
2415
  SELF_REF = '.'
2401
2416
  PARENT = '..'
@@ -2569,7 +2584,7 @@ module Addressable
2569
2584
  @query = nil
2570
2585
  end
2571
2586
 
2572
- NONE = Object.new.freeze
2587
+ NONE = Module.new.freeze
2573
2588
 
2574
2589
  private_constant :NONE
2575
2590
  end
@@ -23,7 +23,7 @@ if !defined?(Addressable::VERSION)
23
23
  module VERSION
24
24
  MAJOR = 2
25
25
  MINOR = 8
26
- TINY = 3
26
+ TINY = 5
27
27
 
28
28
  STRING = [MAJOR, MINOR, TINY].join('.')
29
29
  end
@@ -20,6 +20,7 @@ require "spec_helper"
20
20
  require "addressable/uri"
21
21
  require "uri"
22
22
  require "ipaddr"
23
+ require "yaml"
23
24
 
24
25
  if !"".respond_to?("force_encoding")
25
26
  class String
@@ -6768,6 +6769,37 @@ describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
6768
6769
  end
6769
6770
  end
6770
6771
 
6772
+ describe Addressable::URI, "support serialization roundtrip" do
6773
+ before do
6774
+ @uri = Addressable::URI.new(
6775
+ :scheme => "http",
6776
+ :user => "user",
6777
+ :password => "password",
6778
+ :host => "example.com",
6779
+ :port => 80,
6780
+ :path => "/path",
6781
+ :query => "query=value",
6782
+ :fragment => "fragment"
6783
+ )
6784
+ end
6785
+
6786
+ it "is in a working state after being serialized with Marshal" do
6787
+ @uri = Addressable::URI.parse("http://example.com")
6788
+ cloned_uri = Marshal.load(Marshal.dump(@uri))
6789
+ expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme
6790
+ end
6791
+
6792
+ it "is in a working state after being serialized with YAML" do
6793
+ @uri = Addressable::URI.parse("http://example.com")
6794
+ cloned_uri = if YAML.respond_to?(:unsafe_load)
6795
+ YAML.unsafe_load(YAML.dump(@uri))
6796
+ else
6797
+ YAML.load(YAML.dump(@uri))
6798
+ end
6799
+ expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme
6800
+ end
6801
+ end
6802
+
6771
6803
  describe Addressable::URI, "when initialized in a non-main `Ractor`" do
6772
6804
  it "should have the same value as if used in the main `Ractor`" do
6773
6805
  pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor)
@@ -6799,3 +6831,10 @@ describe Addressable::URI, "when deferring validation" do
6799
6831
  expect(res).to be nil
6800
6832
  end
6801
6833
  end
6834
+
6835
+ describe Addressable::URI, "YAML safe loading" do
6836
+ it "doesn't serialize anonymous objects" do
6837
+ url = Addressable::URI.parse("http://example.com/")
6838
+ expect(YAML.dump(url)).to_not include("!ruby/object {}")
6839
+ end
6840
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.3
4
+ version: 2.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.8
112
+ rubygems_version: 3.4.18
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: URI Implementation