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
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# coding: utf-8
|
4
3
|
# Copyright (C) Bob Aman
|
5
4
|
#
|
6
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -21,6 +20,7 @@ require "spec_helper"
|
|
21
20
|
require "addressable/uri"
|
22
21
|
require "uri"
|
23
22
|
require "ipaddr"
|
23
|
+
require "yaml"
|
24
24
|
|
25
25
|
if !"".respond_to?("force_encoding")
|
26
26
|
class String
|
@@ -999,6 +999,72 @@ describe Addressable::URI, "when frozen" do
|
|
999
999
|
end
|
1000
1000
|
end
|
1001
1001
|
|
1002
|
+
describe Addressable::URI, "when normalized and then deeply frozen" do
|
1003
|
+
before do
|
1004
|
+
@uri = Addressable::URI.parse(
|
1005
|
+
"http://user:password@example.com:8080/path?query=value#fragment"
|
1006
|
+
).normalize!
|
1007
|
+
|
1008
|
+
@uri.instance_variables.each do |var|
|
1009
|
+
@uri.instance_variable_set(var, @uri.instance_variable_get(var).freeze)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
@uri.freeze
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
it "#normalized_scheme should not error" do
|
1016
|
+
expect { @uri.normalized_scheme }.not_to raise_error
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
it "#normalized_user should not error" do
|
1020
|
+
expect { @uri.normalized_user }.not_to raise_error
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
it "#normalized_password should not error" do
|
1024
|
+
expect { @uri.normalized_password }.not_to raise_error
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
it "#normalized_userinfo should not error" do
|
1028
|
+
expect { @uri.normalized_userinfo }.not_to raise_error
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
it "#normalized_host should not error" do
|
1032
|
+
expect { @uri.normalized_host }.not_to raise_error
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
it "#normalized_authority should not error" do
|
1036
|
+
expect { @uri.normalized_authority }.not_to raise_error
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
it "#normalized_port should not error" do
|
1040
|
+
expect { @uri.normalized_port }.not_to raise_error
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
it "#normalized_site should not error" do
|
1044
|
+
expect { @uri.normalized_site }.not_to raise_error
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
it "#normalized_path should not error" do
|
1048
|
+
expect { @uri.normalized_path }.not_to raise_error
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
it "#normalized_query should not error" do
|
1052
|
+
expect { @uri.normalized_query }.not_to raise_error
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
it "#normalized_fragment should not error" do
|
1056
|
+
expect { @uri.normalized_fragment }.not_to raise_error
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
it "should be frozen" do
|
1060
|
+
expect(@uri).to be_frozen
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
it "should not allow destructive operations" do
|
1064
|
+
expect { @uri.normalize! }.to raise_error(RuntimeError)
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
|
1002
1068
|
describe Addressable::URI, "when created from string components" do
|
1003
1069
|
before do
|
1004
1070
|
@uri = Addressable::URI.new(
|
@@ -2956,6 +3022,20 @@ describe Addressable::URI, "when parsed from " +
|
|
2956
3022
|
end
|
2957
3023
|
end
|
2958
3024
|
|
3025
|
+
describe Addressable::URI, "when parsed with empty port" do
|
3026
|
+
subject(:uri) do
|
3027
|
+
Addressable::URI.parse("//example.com:")
|
3028
|
+
end
|
3029
|
+
|
3030
|
+
it "should not infer a port" do
|
3031
|
+
expect(uri.port).to be(nil)
|
3032
|
+
end
|
3033
|
+
|
3034
|
+
it "should have a site value of '//example.com'" do
|
3035
|
+
expect(uri.site).to eq("//example.com")
|
3036
|
+
end
|
3037
|
+
end
|
3038
|
+
|
2959
3039
|
describe Addressable::URI, "when parsed from " +
|
2960
3040
|
"'http://example.com/%2E/'" do
|
2961
3041
|
before do
|
@@ -5874,6 +5954,26 @@ describe Addressable::URI, "when normalizing a path with an encoded slash" do
|
|
5874
5954
|
end
|
5875
5955
|
end
|
5876
5956
|
|
5957
|
+
describe Addressable::URI, "when normalizing a path with special unicode" do
|
5958
|
+
it "does not stop at or ignore null bytes" do
|
5959
|
+
expect(Addressable::URI.parse("/path%00segment/").normalize.path).to eq(
|
5960
|
+
"/path%00segment/"
|
5961
|
+
)
|
5962
|
+
end
|
5963
|
+
|
5964
|
+
it "does apply NFC unicode normalization" do
|
5965
|
+
expect(Addressable::URI.parse("/%E2%84%A6").normalize.path).to eq(
|
5966
|
+
"/%CE%A9"
|
5967
|
+
)
|
5968
|
+
end
|
5969
|
+
|
5970
|
+
it "does not apply NFKC unicode normalization" do
|
5971
|
+
expect(Addressable::URI.parse("/%C2%AF%C2%A0").normalize.path).to eq(
|
5972
|
+
"/%C2%AF%C2%A0"
|
5973
|
+
)
|
5974
|
+
end
|
5975
|
+
end
|
5976
|
+
|
5877
5977
|
describe Addressable::URI, "when normalizing a partially encoded string" do
|
5878
5978
|
it "should result in correct percent encoded sequence" do
|
5879
5979
|
expect(Addressable::URI.normalize_component(
|
@@ -5993,6 +6093,11 @@ describe Addressable::URI, "when unencoding a multibyte string" do
|
|
5993
6093
|
expect(Addressable::URI.unencode_component("ski=%BA%DAɫ")).to eq("ski=\xBA\xDAɫ")
|
5994
6094
|
end
|
5995
6095
|
|
6096
|
+
it "should not fail with UTF-8 incompatible string" do
|
6097
|
+
url = "/M%E9/\xE9?p=\xFC".b
|
6098
|
+
expect(Addressable::URI.unencode_component(url)).to eq("/M\xE9/\xE9?p=\xFC")
|
6099
|
+
end
|
6100
|
+
|
5996
6101
|
it "should result in correct percent encoded sequence as a URI" do
|
5997
6102
|
expect(Addressable::URI.unencode(
|
5998
6103
|
"/path?g%C3%BCnther", ::Addressable::URI
|
@@ -6663,3 +6768,73 @@ describe Addressable::URI, "when initializing a subclass of Addressable::URI" do
|
|
6663
6768
|
expect(@uri.class).to eq(@uri.join('path').class)
|
6664
6769
|
end
|
6665
6770
|
end
|
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
|
+
|
6803
|
+
describe Addressable::URI, "when initialized in a non-main `Ractor`" do
|
6804
|
+
it "should have the same value as if used in the main `Ractor`" do
|
6805
|
+
pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor)
|
6806
|
+
main = Addressable::URI.parse("http://example.com")
|
6807
|
+
expect(
|
6808
|
+
Ractor.new { Addressable::URI.parse("http://example.com") }.take
|
6809
|
+
).to eq(main)
|
6810
|
+
end
|
6811
|
+
end
|
6812
|
+
|
6813
|
+
describe Addressable::URI, "when deferring validation" do
|
6814
|
+
subject(:deferred) { uri.instance_variable_get(:@validation_deferred) }
|
6815
|
+
|
6816
|
+
let(:uri) { Addressable::URI.parse("http://example.com") }
|
6817
|
+
|
6818
|
+
it "defers validation within the block" do
|
6819
|
+
uri.defer_validation do
|
6820
|
+
expect(deferred).to be true
|
6821
|
+
end
|
6822
|
+
end
|
6823
|
+
|
6824
|
+
it "always resets deferral afterward" do
|
6825
|
+
expect { uri.defer_validation { raise "boom" } }.to raise_error("boom")
|
6826
|
+
expect(deferred).to be false
|
6827
|
+
end
|
6828
|
+
|
6829
|
+
it "returns nil" do
|
6830
|
+
res = uri.defer_validation {}
|
6831
|
+
expect(res).to be nil
|
6832
|
+
end
|
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
|
data/tasks/gem.rake
CHANGED
@@ -19,9 +19,9 @@ namespace :gem do
|
|
19
19
|
exit(1)
|
20
20
|
end
|
21
21
|
|
22
|
-
s.required_ruby_version = ">= 2.
|
22
|
+
s.required_ruby_version = ">= 2.2"
|
23
23
|
|
24
|
-
s.add_runtime_dependency "public_suffix", ">= 2.0.2", "<
|
24
|
+
s.add_runtime_dependency "public_suffix", ">= 2.0.2", "< 7.0"
|
25
25
|
s.add_development_dependency "bundler", ">= 1.0", "< 3.0"
|
26
26
|
|
27
27
|
s.require_path = "lib"
|
@@ -30,6 +30,9 @@ namespace :gem do
|
|
30
30
|
s.email = "bob@sporkmonger.com"
|
31
31
|
s.homepage = "https://github.com/sporkmonger/addressable"
|
32
32
|
s.license = "Apache-2.0"
|
33
|
+
s.metadata = {
|
34
|
+
"changelog_uri" => "https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md#v#{PKG_VERSION}"
|
35
|
+
}
|
33
36
|
end
|
34
37
|
|
35
38
|
Gem::PackageTask.new(GEM_SPEC) do |p|
|
@@ -53,7 +56,7 @@ namespace :gem do
|
|
53
56
|
|
54
57
|
desc "Install the gem"
|
55
58
|
task :install => ["clobber", "gem:package"] do
|
56
|
-
sh "
|
59
|
+
sh "gem install --local ./pkg/#{GEM_SPEC.full_name}.gem"
|
57
60
|
end
|
58
61
|
|
59
62
|
desc "Uninstall the gem"
|
@@ -62,7 +65,7 @@ namespace :gem do
|
|
62
65
|
if installed_list &&
|
63
66
|
(installed_list.collect { |s| s.version.to_s}.include?(PKG_VERSION))
|
64
67
|
sh(
|
65
|
-
"
|
68
|
+
"gem uninstall --version '#{PKG_VERSION}' " +
|
66
69
|
"--ignore-dependencies --executables #{PKG_NAME}"
|
67
70
|
)
|
68
71
|
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.
|
4
|
+
version: 2.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Aman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: public_suffix
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 2.0.2
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 2.0.2
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,8 @@ files:
|
|
90
90
|
homepage: https://github.com/sporkmonger/addressable
|
91
91
|
licenses:
|
92
92
|
- Apache-2.0
|
93
|
-
metadata:
|
93
|
+
metadata:
|
94
|
+
changelog_uri: https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md#v2.8.7
|
94
95
|
post_install_message:
|
95
96
|
rdoc_options:
|
96
97
|
- "--main"
|
@@ -101,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
102
|
requirements:
|
102
103
|
- - ">="
|
103
104
|
- !ruby/object:Gem::Version
|
104
|
-
version: '2.
|
105
|
+
version: '2.2'
|
105
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
107
|
requirements:
|
107
108
|
- - ">="
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.11
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: URI Implementation
|