From c0cfa04a6601fbabd465a6c3a16a8af997706462 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Mon, 19 Aug 2024 16:42:40 -0700 Subject: [PATCH 01/62] Do not allow empty host names, as they are not allowed by RFC 3986 Pointed out by John Hawthorn. Fixes [Bug #20686] --- lib/uri/http.rb | 12 ++++++++++++ test/uri/test_generic.rb | 6 ++++-- test/uri/test_http.rb | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/uri/http.rb b/lib/uri/http.rb index 900b132..3c41cd4 100644 --- a/lib/uri/http.rb +++ b/lib/uri/http.rb @@ -61,6 +61,18 @@ def self.build(args) super(tmp) end + # Do not allow empty host names, as they are not allowed by RFC 3986. + def check_host(v) + ret = super + + if ret && v.empty? + raise InvalidComponentError, + "bad component(expected host component): #{v}" + end + + ret + end + # # == Description # diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 8209363..ccea6cd 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -828,8 +828,10 @@ def test_ipv6 assert_equal("http://[::1]/bar", u.to_s) u.hostname = "::1" assert_equal("http://[::1]/bar", u.to_s) - u.hostname = "" - assert_equal("http:///bar", u.to_s) + + u = URI("file://foo/bar") + u.hostname = '' + assert_equal("file:///bar", u.to_s) end def test_build diff --git a/test/uri/test_http.rb b/test/uri/test_http.rb index e937b1a..96625a3 100644 --- a/test/uri/test_http.rb +++ b/test/uri/test_http.rb @@ -19,6 +19,10 @@ def test_build assert_kind_of(URI::HTTP, u) end + def test_build_empty_host + assert_raise(URI::InvalidComponentError) { URI::HTTP.build(host: '') } + end + def test_parse u = URI.parse('http://a') assert_kind_of(URI::HTTP, u) From 618e2bb640c3db69c8532187e8db6eba789239e6 Mon Sep 17 00:00:00 2001 From: Nikita Levchuk Date: Wed, 6 Nov 2024 15:08:47 +0100 Subject: [PATCH 02/62] lib/uri/mailto.rb (EMAIL_REGEXP): the local part should not contain leading or trailing dots --- lib/uri/mailto.rb | 2 +- test/uri/test_mailto.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index cb8024f..c5a5e4a 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -52,7 +52,7 @@ class MailTo < Generic HEADER_REGEXP = /\A(?(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g)*\z/ # practical regexp for email address # https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address - EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/ + EMAIL_REGEXP = /\A[^.][a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+[^.]@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/ # :startdoc: # diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index e7d3142..d2e9648 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -148,6 +148,14 @@ def test_check_to assert_raise(URI::InvalidComponentError) do u.to = '@invalid.email' end + + assert_raise(URI::InvalidComponentError) do + u.to = '.hello@invalid.email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'hello.@invalid.email' + end end def test_to_s From 1f3d3df02a0ff764e9a8a80c8d9e2c1e2d11bdce Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 8 Nov 2024 15:05:58 +0900 Subject: [PATCH 03/62] Added more fallback constants like URI::PARTTERN and URI::REGEXP Fixed https://github.com/ruby/uri/issues/125 --- lib/uri/common.rb | 8 +++++++- test/uri/test_common.rb | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index cf93fb1..fe8475f 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -46,9 +46,15 @@ def self.parser=(parser = RFC3986_PARSER) self.parser = RFC3986_PARSER def self.const_missing(const) - if value = RFC2396_PARSER.regexp[const] + if const == :REGEXP + warn "URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.", uplevel: 1 if $VERBOSE + URI::RFC2396_REGEXP + elsif value = RFC2396_PARSER.regexp[const] warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE value + elsif value = RFC2396_Parser.const_get(const) + warn "URI::#{const} is obsolete. Use RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE + value else super end diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index bccdeaf..176efb8 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -13,8 +13,12 @@ def teardown def test_fallback_constants orig_verbose = $VERBOSE $VERBOSE = nil - assert URI::ABS_URI + assert_raise(NameError) { URI::FOO } + + assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] + assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN + assert_equal URI::REGEXP, URI::RFC2396_REGEXP ensure $VERBOSE = orig_verbose end From 3011eb6f6e53c7870f91404d4a789cb854c893ad Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 8 Nov 2024 15:07:36 +0900 Subject: [PATCH 04/62] Bump up v1.0.1 --- lib/uri/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uri/version.rb b/lib/uri/version.rb index c68c43a..e74ddec 100644 --- a/lib/uri/version.rb +++ b/lib/uri/version.rb @@ -1,6 +1,6 @@ module URI # :stopdoc: - VERSION_CODE = '010000'.freeze + VERSION_CODE = '010001'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end From c191b627cbe5a8a735fd9e6f1eaa3b92ea901f43 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 8 Nov 2024 11:57:18 -0500 Subject: [PATCH 05/62] Fix minor typo from 9997c1acee --- lib/uri/rfc3986_parser.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 4000f13..0b5f0c4 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -142,25 +142,25 @@ def join(*uris) # :nodoc: # Compatibility for RFC2396 parser def extract(str, schemes = nil, &block) # :nodoc: - warn "URI::RFC3986_PARSER.extract is obsoleted. Use URI::RFC2396_PARSER.extract explicitly.", uplevel: 1 if $VERBOSE + warn "URI::RFC3986_PARSER.extract is obsolete. Use URI::RFC2396_PARSER.extract explicitly.", uplevel: 1 if $VERBOSE RFC2396_PARSER.extract(str, schemes, &block) end # Compatibility for RFC2396 parser def make_regexp(schemes = nil) # :nodoc: - warn "URI::RFC3986_PARSER.make_regexp is obsoleted. Use URI::RFC2396_PARSER.make_regexp explicitly.", uplevel: 1 if $VERBOSE + warn "URI::RFC3986_PARSER.make_regexp is obsolete. Use URI::RFC2396_PARSER.make_regexp explicitly.", uplevel: 1 if $VERBOSE RFC2396_PARSER.make_regexp(schemes) end # Compatibility for RFC2396 parser def escape(str, unsafe = nil) # :nodoc: - warn "URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.", uplevel: 1 if $VERBOSE + warn "URI::RFC3986_PARSER.escape is obsolete. Use URI::RFC2396_PARSER.escape explicitly.", uplevel: 1 if $VERBOSE unsafe ? RFC2396_PARSER.escape(str, unsafe) : RFC2396_PARSER.escape(str) end # Compatibility for RFC2396 parser def unescape(str, escaped = nil) # :nodoc: - warn "URI::RFC3986_PARSER.unescape is obsoleted. Use URI::RFC2396_PARSER.unescape explicitly.", uplevel: 1 if $VERBOSE + warn "URI::RFC3986_PARSER.unescape is obsolete. Use URI::RFC2396_PARSER.unescape explicitly.", uplevel: 1 if $VERBOSE escaped ? RFC2396_PARSER.unescape(str, escaped) : RFC2396_PARSER.unescape(str) end From f0847c266cd5d427559a3bec1449fee6613e7d06 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:34:33 +1100 Subject: [PATCH 06/62] Remove unused files from the gem package --- uri.gemspec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/uri.gemspec b/uri.gemspec index 9cf0a71..9c4d43e 100644 --- a/uri.gemspec +++ b/uri.gemspec @@ -30,8 +30,11 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + gemspec = File.basename(__FILE__) spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject do |file| + (file == gemspec) || file.start_with?(*%w[bin/ test/ .github/ .gitignore Gemfile Rakefile]) + end end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } From ee9a38701a3d49b7d56f7e7a1fd846333186d748 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 12:01:06 +0900 Subject: [PATCH 07/62] Restore constants like URI::REGEXP::PATTERN::IPV6ADDR --- lib/uri/rfc2396_parser.rb | 7 +++++++ test/uri/test_common.rb | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index a56ca34..c112b1b 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -536,4 +536,11 @@ def convert_to_uri(uri) end end # class Parser + + # Backward compatibility for URI::REGEXP::PATTERN::* + RFC2396_Parser.new.pattern.each_pair do |sym, str| + unless RFC2396_REGEXP::PATTERN.const_defined?(sym) + RFC2396_REGEXP::PATTERN.const_set(sym, str) + end + end end # module URI diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 176efb8..b1e3b2b 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -10,6 +10,10 @@ def setup def teardown end + class Foo + include URI::REGEXP::PATTERN + end + def test_fallback_constants orig_verbose = $VERBOSE $VERBOSE = nil @@ -19,6 +23,8 @@ def test_fallback_constants assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN assert_equal URI::REGEXP, URI::RFC2396_REGEXP + assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN + assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR ensure $VERBOSE = orig_verbose end From 60a8bc15759065762fda95e83f383747904089a8 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 12:02:46 +0900 Subject: [PATCH 08/62] Removed duplicated declare step for constants under the URI::RFC2396_REGEXP::PATTERN --- lib/uri/common.rb | 5 ----- test/uri/test_common.rb | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index fe8475f..f13ff1a 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -31,11 +31,6 @@ def self.parser=(parser = RFC3986_PARSER) if Parser == RFC2396_Parser const_set("REGEXP", URI::RFC2396_REGEXP) const_set("PATTERN", URI::RFC2396_REGEXP::PATTERN) - Parser.new.pattern.each_pair do |sym, str| - unless REGEXP::PATTERN.const_defined?(sym) - REGEXP::PATTERN.const_set(sym, str) - end - end end Parser.new.regexp.each_pair do |sym, str| diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index b1e3b2b..e96f819 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -40,6 +40,7 @@ def test_parser_switch assert defined?(URI::REGEXP) assert defined?(URI::PATTERN) assert defined?(URI::PATTERN::ESCAPED) + assert defined?(URI::REGEXP::PATTERN::IPV6ADDR) URI.parser = URI::RFC3986_PARSER From a0dd612e9070c979f20ccf4308f6aa10690c1d68 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:20:46 +1100 Subject: [PATCH 09/62] Remove rakelib/ dir from gem also --- uri.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uri.gemspec b/uri.gemspec index 9c4d43e..0d0f897 100644 --- a/uri.gemspec +++ b/uri.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| gemspec = File.basename(__FILE__) spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject do |file| - (file == gemspec) || file.start_with?(*%w[bin/ test/ .github/ .gitignore Gemfile Rakefile]) + (file == gemspec) || file.start_with?(*%w[bin/ test/ rakelib/ .github/ .gitignore Gemfile Rakefile]) end end spec.bindir = "exe" From 57ee11f55f34bd89097fae12839d565b20fa6ca1 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 14:03:06 +0900 Subject: [PATCH 10/62] Don't use bundle exec --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f0e6b5d..1d70fe5 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -30,7 +30,7 @@ jobs: uses: actions/configure-pages@v5 - name: Build with RDoc # Outputs to the './_site' directory by default - run: bundle exec rake rdoc + run: rake rdoc - name: Upload artifact uses: actions/upload-pages-artifact@v3 From 0a042e862650f085bc7bc55f5a1cdcea52b486e4 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 14:05:50 +0900 Subject: [PATCH 11/62] Fixed rake rdoc --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 19de93e..3935fdf 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ require "rdoc/task" RDoc::Task.new do |doc| doc.main = "README.md" doc.title = "URI - handle Uniform Resource Identifiers" - doc.rdoc_files = FileList.new %w[lib README.md LICENSE.txt] + doc.rdoc_files = FileList.new %w[lib README.md BSDL COPYING] doc.rdoc_dir = "_site" # for github pages end From b6f583369a2c0f31a8aeff488d1e9c0bf05edac6 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 14 Nov 2024 11:58:08 +0900 Subject: [PATCH 12/62] Check existence constants only URI module --- lib/uri/common.rb | 2 +- lib/uri/rfc2396_parser.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index f13ff1a..c3fe0b4 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -34,7 +34,7 @@ def self.parser=(parser = RFC3986_PARSER) end Parser.new.regexp.each_pair do |sym, str| - remove_const(sym) if const_defined?(sym) + remove_const(sym) if const_defined?(sym, false) const_set(sym, str) end end diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index c112b1b..0336366 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -539,7 +539,7 @@ def convert_to_uri(uri) # Backward compatibility for URI::REGEXP::PATTERN::* RFC2396_Parser.new.pattern.each_pair do |sym, str| - unless RFC2396_REGEXP::PATTERN.const_defined?(sym) + unless RFC2396_REGEXP::PATTERN.const_defined?(sym, false) RFC2396_REGEXP::PATTERN.const_set(sym, str) end end From e46960a467f2ed398731286ec78b899e1a01655f Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 14 Nov 2024 12:48:33 +0900 Subject: [PATCH 13/62] Bump up v1.0.2 --- lib/uri/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uri/version.rb b/lib/uri/version.rb index e74ddec..59f1c82 100644 --- a/lib/uri/version.rb +++ b/lib/uri/version.rb @@ -1,6 +1,6 @@ module URI # :stopdoc: - VERSION_CODE = '010001'.freeze + VERSION_CODE = '010002'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end From 0524ed1137b709ac75897e57abc9e9a85f1a1573 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:54:34 +0000 Subject: [PATCH 14/62] Bump step-security/harden-runner from 2.10.1 to 2.10.2 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.10.1 to 2.10.2. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/91182cccc01eb5e619899d80e4e971d6181294a7...0080882f6c36860b6ba35c610c98ce87d4e2f26f) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index e15d54b..7f23d56 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit From ad3f10123ec4925efed33b2f9cd221a052391841 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:54:39 +0000 Subject: [PATCH 15/62] Bump rubygems/release-gem Bumps [rubygems/release-gem](https://github.com/rubygems/release-gem) from 612653d273a73bdae1df8453e090060bb4db5f31 to 9e85cb11501bebc2ae661c1500176316d3987059. - [Release notes](https://github.com/rubygems/release-gem/releases) - [Commits](https://github.com/rubygems/release-gem/compare/612653d273a73bdae1df8453e090060bb4db5f31...9e85cb11501bebc2ae661c1500176316d3987059) --- updated-dependencies: - dependency-name: rubygems/release-gem dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index e15d54b..569997e 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -36,7 +36,7 @@ jobs: ruby-version: ruby - name: Publish to RubyGems - uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1 + uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1 - name: Create GitHub release run: | From be0a095cf8f8f8ce2d26c6b8ddd4b20e463f6521 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 25 Nov 2024 12:36:36 +0900 Subject: [PATCH 16/62] Fixed version number of rubygems/release-gem --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 986bd7d..2f34c79 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -36,7 +36,7 @@ jobs: ruby-version: ruby - name: Publish to RubyGems - uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1 + uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1.1.0 - name: Create GitHub release run: | From c00726a20a006e3a81bee19650e7830213cfabad Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 25 Nov 2024 16:28:48 +0900 Subject: [PATCH 17/62] Prevent a warning: URI::REGEXP is obsolete (#138) --- test/uri/test_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index e96f819..774eb91 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -11,7 +11,7 @@ def teardown end class Foo - include URI::REGEXP::PATTERN + include URI::RFC2396_REGEXP::PATTERN end def test_fallback_constants From 22f5a7a7906e347a49b7b888339d31825b31de4d Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 26 Nov 2024 10:32:51 +0900 Subject: [PATCH 18/62] Revert "Prevent a warning: URI::REGEXP is obsolete (#138)" This reverts commit c00726a20a006e3a81bee19650e7830213cfabad. --- test/uri/test_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 774eb91..e96f819 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -11,7 +11,7 @@ def teardown end class Foo - include URI::RFC2396_REGEXP::PATTERN + include URI::REGEXP::PATTERN end def test_fallback_constants From bd2e4be9d0fa4937efa7811a999f5820ea868a9f Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 26 Nov 2024 10:47:12 +0900 Subject: [PATCH 19/62] Suppress deprecate warning of test class and use EnvUtil.suppress_warning. --- test/uri/test_common.rb | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index e96f819..1e28347 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -10,23 +10,20 @@ def setup def teardown end - class Foo - include URI::REGEXP::PATTERN - end - - def test_fallback_constants - orig_verbose = $VERBOSE - $VERBOSE = nil + EnvUtil.suppress_warning do + class Foo + include URI::REGEXP::PATTERN + end - assert_raise(NameError) { URI::FOO } + def test_fallback_constants + assert_raise(NameError) { URI::FOO } - assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] - assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN - assert_equal URI::REGEXP, URI::RFC2396_REGEXP - assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN - assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR - ensure - $VERBOSE = orig_verbose + assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] + assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN + assert_equal URI::REGEXP, URI::RFC2396_REGEXP + assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN + assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR + end end def test_parser_switch From bdf765e44a51d725d7189d7e8343ce807410aee6 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 26 Nov 2024 19:02:53 +0900 Subject: [PATCH 20/62] Suppress deprecate warning of test class (retry) (#140) A follow-up to bd2e4be9d0fa4937efa7811a999f5820ea868a9f Also, leave a comment that the use of `URI::REGEXP` is intentional --- test/uri/test_common.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 1e28347..6326aec 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -12,10 +12,13 @@ def teardown EnvUtil.suppress_warning do class Foo + # Intentionally use `URI::REGEXP`, which is for the compatibility include URI::REGEXP::PATTERN end + end - def test_fallback_constants + def test_fallback_constants + EnvUtil.suppress_warning do assert_raise(NameError) { URI::FOO } assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] From 2d7d2d9988c2a2438a47525ad48ee2481e344eb8 Mon Sep 17 00:00:00 2001 From: Nikita Levchuk Date: Fri, 6 Dec 2024 11:56:03 +0100 Subject: [PATCH 21/62] lib/uri/mailto.rb (EMAIL_REGEXP): use assertions surrounding the local part instead of a character class --- lib/uri/mailto.rb | 2 +- test/uri/test_mailto.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index c5a5e4a..a15d2f0 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -52,7 +52,7 @@ class MailTo < Generic HEADER_REGEXP = /\A(?(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g)*\z/ # practical regexp for email address # https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address - EMAIL_REGEXP = /\A[^.][a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+[^.]@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/ + EMAIL_REGEXP = /\A(?!\.)[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+(? Date: Mon, 16 Dec 2024 15:17:53 +0900 Subject: [PATCH 22/62] Now, URI library uses RFC3986 parser as default --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3775f3b..5c7c0dd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI](https://github.com/ruby/uri/actions/workflows/test.yml/badge.svg)](https://github.com/ruby/uri/actions/workflows/test.yml) [![Yard Docs](https://img.shields.io/badge/docs-exist-blue.svg)](https://ruby.github.io/uri/) -URI is a module providing classes to handle Uniform Resource Identifiers [RFC2396](http://tools.ietf.org/html/rfc2396). +URI is a module providing classes to handle Uniform Resource Identifiers [RFC3986](http://tools.ietf.org/html/rfc3986). ## Features From 9ea0783d321793dcb6563d9fb1dbea2cba3523af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 00:58:54 +0000 Subject: [PATCH 23/62] Bump rubygems/release-gem from 1.1.0 to 1.1.1 Bumps [rubygems/release-gem](https://github.com/rubygems/release-gem) from 1.1.0 to 1.1.1. - [Release notes](https://github.com/rubygems/release-gem/releases) - [Commits](https://github.com/rubygems/release-gem/compare/9e85cb11501bebc2ae661c1500176316d3987059...a25424ba2ba8b387abc8ef40807c2c85b96cbe32) --- updated-dependencies: - dependency-name: rubygems/release-gem dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 2f34c79..74d6d2a 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -36,7 +36,7 @@ jobs: ruby-version: ruby - name: Publish to RubyGems - uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1.1.0 + uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1 - name: Create GitHub release run: | From f7589d5f622afe9790ed1cc266326a9911bbc0df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 00:39:23 +0000 Subject: [PATCH 24/62] Bump step-security/harden-runner from 2.10.2 to 2.10.3 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.10.2 to 2.10.3. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/0080882f6c36860b6ba35c610c98ce87d4e2f26f...c95a14d0e5bab51a9f56296a4eb0e416910cd350) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 74d6d2a..9ae544e 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 + uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3 with: egress-policy: audit From 7e2142f49d03539df63f5e92e98390d9f1f6ff6c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 00:59:42 +0000 Subject: [PATCH 25/62] Bump step-security/harden-runner from 2.10.3 to 2.10.4 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.10.3 to 2.10.4. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/c95a14d0e5bab51a9f56296a4eb0e416910cd350...cb605e52c26070c328afc4562f0b4ada7618a84e) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 9ae544e..5ce7869 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3 + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 with: egress-policy: audit From fec924238f8bb16871efbe4d8dfa022e5d54db41 Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Thu, 23 Jan 2025 17:44:17 +0900 Subject: [PATCH 26/62] Fix the mention to removed `URI.escape/URI::Escape` This was removed by #9. --- lib/uri/file.rb | 2 +- lib/uri/generic.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/uri/file.rb b/lib/uri/file.rb index 940d361..47b5aef 100644 --- a/lib/uri/file.rb +++ b/lib/uri/file.rb @@ -47,7 +47,7 @@ class File < Generic # :path => '/ruby/src'}) # uri2.to_s # => "file://host.example.com/ruby/src" # - # uri3 = URI::File.build({:path => URI::escape('/path/my file.txt')}) + # uri3 = URI::File.build({:path => URI::RFC2396_PARSER.escape('/path/my file.txt')}) # uri3.to_s # => "file:///path/my%20file.txt" # def self.build(args) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index d4bfa3b..07346c6 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -73,7 +73,7 @@ def self.use_registry # :nodoc: # # At first, tries to create a new URI::Generic instance using # URI::Generic::build. But, if exception URI::InvalidComponentError is raised, - # then it does URI::Escape.escape all URI components and tries again. + # then it does URI::RFC2396_PARSER.escape all URI components and tries again. # def self.build2(args) begin From aa45e72407f7e0da35cdf890f5bad73da2284ece Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 23 Jan 2025 22:50:41 +0900 Subject: [PATCH 27/62] [DOC] Add config files for RDoc --- .document | 4 ++++ .rdoc_options | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 .document create mode 100644 .rdoc_options diff --git a/.document b/.document new file mode 100644 index 0000000..e2b9569 --- /dev/null +++ b/.document @@ -0,0 +1,4 @@ +BSDL +COPYING +README.md +lib/ diff --git a/.rdoc_options b/.rdoc_options new file mode 100644 index 0000000..b1f9cda --- /dev/null +++ b/.rdoc_options @@ -0,0 +1,4 @@ +main_page: README.md +op_dir: _site +warn_missing_rdoc_ref: true +title: URI Documentation From fe7aa3dac2b3415758635a616ce44afb15bf4900 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 23 Jan 2025 22:55:31 +0900 Subject: [PATCH 28/62] [DOC] Make documentation 100% --- .document | 1 + docs/kernel.rb | 2 ++ lib/uri/common.rb | 10 +++++++--- lib/uri/generic.rb | 8 +++++--- lib/uri/rfc2396_parser.rb | 12 ++++++------ 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 docs/kernel.rb diff --git a/.document b/.document index e2b9569..1d07bdf 100644 --- a/.document +++ b/.document @@ -1,4 +1,5 @@ BSDL COPYING README.md +docs/ lib/ diff --git a/docs/kernel.rb b/docs/kernel.rb new file mode 100644 index 0000000..68ed335 --- /dev/null +++ b/docs/kernel.rb @@ -0,0 +1,2 @@ +# :stopdoc: +module Kernel end diff --git a/lib/uri/common.rb b/lib/uri/common.rb index c3fe0b4..bf28dea 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -13,15 +13,19 @@ require_relative "rfc3986_parser" module URI + # The default parser instance for RFC 2396. RFC2396_PARSER = RFC2396_Parser.new Ractor.make_shareable(RFC2396_PARSER) if defined?(Ractor) + # The default parser instance for RFC 3986. RFC3986_PARSER = RFC3986_Parser.new Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor) + # The default parser instance. DEFAULT_PARSER = RFC3986_PARSER Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor) + # Set the default parser instance. def self.parser=(parser = RFC3986_PARSER) remove_const(:Parser) if defined?(::URI::Parser) const_set("Parser", parser.class) @@ -40,7 +44,7 @@ def self.parser=(parser = RFC3986_PARSER) end self.parser = RFC3986_PARSER - def self.const_missing(const) + def self.const_missing(const) # :nodoc: if const == :REGEXP warn "URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.", uplevel: 1 if $VERBOSE URI::RFC2396_REGEXP @@ -87,7 +91,7 @@ def make_components_hash(klass, array_hash) module_function :make_components_hash end - module Schemes + module Schemes # :nodoc: end private_constant :Schemes @@ -305,7 +309,7 @@ def self.regexp(schemes = nil)# :nodoc: 256.times do |i| TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i) end - TBLENCURICOMP_ = TBLENCWWWCOMP_.dup.freeze + TBLENCURICOMP_ = TBLENCWWWCOMP_.dup.freeze # :nodoc: TBLENCWWWCOMP_[' '] = '+' TBLENCWWWCOMP_.freeze TBLDECWWWCOMP_ = {} # :nodoc: diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index d4bfa3b..f5cdb73 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -737,12 +737,12 @@ def check_registry(v) # :nodoc: end private :check_registry - def set_registry(v) #:nodoc: + def set_registry(v) # :nodoc: raise InvalidURIError, "cannot set registry" end protected :set_registry - def registry=(v) + def registry=(v) # :nodoc: raise InvalidURIError, "cannot set registry" end @@ -1392,10 +1392,12 @@ def ==(oth) end end + # Returns the hash value. def hash self.component_ary.hash end + # Compares with _oth_ for Hash. def eql?(oth) self.class == oth.class && parser == oth.parser && @@ -1438,7 +1440,7 @@ def select(*components) end end - def inspect + def inspect # :nodoc: "#<#{self.class} #{self}>" end diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index 0336366..75a2d2d 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -321,14 +321,14 @@ def unescape(str, escaped = @regexp[:ESCAPED]) str.gsub(escaped) { [$&[1, 2]].pack('H2').force_encoding(enc) } end - @@to_s = Kernel.instance_method(:to_s) - if @@to_s.respond_to?(:bind_call) - def inspect - @@to_s.bind_call(self) + TO_S = Kernel.instance_method(:to_s) # :nodoc: + if TO_S.respond_to?(:bind_call) + def inspect # :nodoc: + TO_S.bind_call(self) end else - def inspect - @@to_s.bind(self).call + def inspect # :nodoc: + TO_S.bind(self).call end end From 428eb10e44dd2ca3dee80bbc9ab774259a65286a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 2 Feb 2025 16:11:09 +0900 Subject: [PATCH 29/62] Use a fully qualified name in warning messages Currently, some warning messages don't contain a `URI` like the following. ```ruby warning: URI::ABS_URI is obsolete. Use RFC2396_PARSER.regexp[:ABS_URI] explicitly. ``` But, without `URI` prefix, the suggested value doesn't work. So I think we should use a fully qualified name to avoid confusion. --- lib/uri/common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index bf28dea..db19e8e 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -49,10 +49,10 @@ def self.const_missing(const) # :nodoc: warn "URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.", uplevel: 1 if $VERBOSE URI::RFC2396_REGEXP elsif value = RFC2396_PARSER.regexp[const] - warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE + warn "URI::#{const} is obsolete. Use URI::RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE value elsif value = RFC2396_Parser.const_get(const) - warn "URI::#{const} is obsolete. Use RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE + warn "URI::#{const} is obsolete. Use URI::RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE value else super From c0594630f0219ffb48f1f2a9bd2621ecf055b39b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 00:32:40 +0000 Subject: [PATCH 30/62] Bump step-security/harden-runner from 2.10.4 to 2.11.0 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.10.4 to 2.11.0. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/cb605e52c26070c328afc4562f0b4ada7618a84e...4d991eb9b905ef189e4c376166672c3f2f230481) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 5ce7869..9eb2e2a 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 with: egress-policy: audit From 3675494839112b64d5f082a9068237b277ed1495 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 21 Feb 2025 16:29:36 +0900 Subject: [PATCH 31/62] Truncate userinfo with URI#join, URI#merge and URI#+ --- lib/uri/generic.rb | 6 +++++- test/uri/test_generic.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index f5cdb73..cd3aa23 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1141,7 +1141,11 @@ def merge(oth) end # RFC2396, Section 5.2, 7) - base.set_userinfo(rel.userinfo) if rel.userinfo + if rel.userinfo + base.set_userinfo(rel.userinfo) + else + base.set_userinfo(nil) + end base.set_host(rel.host) if rel.host base.set_port(rel.port) if rel.port base.query = rel.query if rel.query diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 8209363..4b04998 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -175,6 +175,17 @@ def test_parse # must be empty string to identify as path-abempty, not path-absolute assert_equal('', url.host) assert_equal('http:////example.com', url.to_s) + + # sec-2957667 + url = URI.parse('http://user:pass@example.com').merge('//example.net') + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) + url = URI.join('http://user:pass@example.com', '//example.net') + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) + url = URI.parse('http://user:pass@example.com') + '//example.net' + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) end def test_parse_scheme_with_symbols From 2789182478f42ccbb62197f952eb730e4f02bfc5 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 21 Feb 2025 18:16:28 +0900 Subject: [PATCH 32/62] Fix merger of URI with authority component https://hackerone.com/reports/2957667 Co-authored-by: Nobuyoshi Nakada --- lib/uri/generic.rb | 19 +++++++------------ test/uri/test_generic.rb | 7 +++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index cd3aa23..b574104 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1133,21 +1133,16 @@ def merge(oth) base.fragment=(nil) # RFC2396, Section 5.2, 4) - if !authority - base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path - else - # RFC2396, Section 5.2, 4) - base.set_path(rel.path) if rel.path + if authority + base.set_userinfo(rel.userinfo) + base.set_host(rel.host) + base.set_port(rel.port || base.default_port) + base.set_path(rel.path) + elsif base.path && rel.path + base.set_path(merge_path(base.path, rel.path)) end # RFC2396, Section 5.2, 7) - if rel.userinfo - base.set_userinfo(rel.userinfo) - else - base.set_userinfo(nil) - end - base.set_host(rel.host) if rel.host - base.set_port(rel.port) if rel.port base.query = rel.query if rel.query base.fragment=(rel.fragment) if rel.fragment diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 4b04998..1d5fbc7 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -278,6 +278,13 @@ def test_merge assert_equal(u0, u1) end + def test_merge_authority + u = URI.parse('http://user:pass@example.com:8080') + u0 = URI.parse('http://new.example.org/path') + u1 = u.merge('//new.example.org/path') + assert_equal(u0, u1) + end + def test_route url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html') assert_equal('b.html', url.to_s) From 3213f4a0f80f10c8f36993dbb9eabe7f2c1b50fd Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 26 Feb 2025 16:12:46 +0900 Subject: [PATCH 33/62] Bump up v1.0.3 --- lib/uri/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uri/version.rb b/lib/uri/version.rb index 59f1c82..b6a8ce1 100644 --- a/lib/uri/version.rb +++ b/lib/uri/version.rb @@ -1,6 +1,6 @@ module URI # :stopdoc: - VERSION_CODE = '010002'.freeze + VERSION_CODE = '010003'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end From 602e2b347a6ee1642cc04ed8d5659a03814d3762 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 27 Feb 2025 11:11:37 +0900 Subject: [PATCH 34/62] Update to use the latest version of setup-ruby and bump up to Ruby 3.4 --- .github/workflows/gh-pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 1d70fe5..e7ee429 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -21,9 +21,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Setup Ruby - uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # v1.152.0 + uses: ruby/setup-ruby@32110d4e311bd8996b2a82bf2a43b714ccc91777 # v1.221.0 with: - ruby-version: '3.3' + ruby-version: '3.4' bundler-cache: true - name: Setup Pages id: pages From 38ea6c6f5fceb264d2e4aaed0c1ad2c0e65b1a03 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 00:06:13 +0000 Subject: [PATCH 35/62] Bump step-security/harden-runner from 2.11.0 to 2.11.1 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.11.0 to 2.11.1. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/4d991eb9b905ef189e4c376166672c3f2f230481...c6295a65d1254861815972266d5933fd6e532bdf) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.11.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 9eb2e2a..5779c20 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit From 917be23dee555ebadb54ac6a932e0c719609d095 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Apr 2025 00:35:26 +0000 Subject: [PATCH 36/62] Bump step-security/harden-runner from 2.11.1 to 2.12.0 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.11.1 to 2.12.0. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/c6295a65d1254861815972266d5933fd6e532bdf...0634a2670c59f64b4a01f0f96f84700a4088b9f0) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.12.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 5779c20..df5b8d5 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 with: egress-policy: audit From 324a7d5e2fef3c2304af6883100fcad2c503d0ef Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Tue, 27 May 2025 03:58:04 +0900 Subject: [PATCH 37/62] `Ractor::Port` * Added `Ractor::Port` * `Ractor::Port#receive` (support multi-threads) * `Rcator::Port#close` * `Ractor::Port#closed?` * Added some methods * `Ractor#join` * `Ractor#value` * `Ractor#monitor` * `Ractor#unmonitor` * Removed some methods * `Ractor#take` * `Ractor.yield` * Change the spec * `Racotr.select` You can wait for multiple sequences of messages with `Ractor::Port`. ```ruby ports = 3.times.map{ Ractor::Port.new } ports.map.with_index do |port, ri| Ractor.new port,ri do |port, ri| 3.times{|i| port << "r#{ri}-#{i}"} end end p ports.each{|port| pp 3.times.map{port.receive}} ``` In this example, we use 3 ports, and 3 Ractors send messages to them respectively. We can receive a series of messages from each port. You can use `Ractor#value` to get the last value of a Ractor's block: ```ruby result = Ractor.new do heavy_task() end.value ``` You can wait for the termination of a Ractor with `Ractor#join` like this: ```ruby Ractor.new do some_task() end.join ``` `#value` and `#join` are similar to `Thread#value` and `Thread#join`. To implement `#join`, `Ractor#monitor` (and `Ractor#unmonitor`) is introduced. This commit changes `Ractor.select()` method. It now only accepts ports or Ractors, and returns when a port receives a message or a Ractor terminates. We removes `Ractor.yield` and `Ractor#take` because: * `Ractor::Port` supports most of similar use cases in a simpler manner. * Removing them significantly simplifies the code. We also change the internal thread scheduler code (thread_pthread.c): * During barrier synchronization, we keep the `ractor_sched` lock to avoid deadlocks. This lock is released by `rb_ractor_sched_barrier_end()` which is called at the end of operations that require the barrier. * fix potential deadlock issues by checking interrupts just before setting UBF. https://bugs.ruby-lang.org/issues/21262 --- test/uri/test_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 6326aec..fef785a 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -75,7 +75,7 @@ def test_ractor return unless defined?(Ractor) assert_ractor(<<~RUBY, require: 'uri') r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect } - assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.take) + assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.value) RUBY end From 443ed0cf8540588b3e4e9bf8b52cb8834f13c8bc Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 3 Jun 2025 16:55:28 +0900 Subject: [PATCH 38/62] Alias value or join to take in old Ruby --- test/uri/test_common.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index fef785a..fef3f70 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -74,6 +74,9 @@ def test_extract def test_ractor return unless defined?(Ractor) assert_ractor(<<~RUBY, require: 'uri') + class Ractor + alias value take unless method_defined? :value # compat with Ruby 3.4 and olders + end r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect } assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.value) RUBY From 40e94cac119c309d3c25416351471cbb7ff5cb23 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 4 Jun 2025 14:32:51 +0900 Subject: [PATCH 39/62] Use the latest version of assert_ractor for Ractor#value --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ba909e8..6669eae 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,5 @@ group :development do gem "bundler" gem "rake" gem "test-unit" - gem "test-unit-ruby-core" + gem "test-unit-ruby-core", ">= 1.0.7" end From 9e51838a04713b6cf21e9de9ccaf919884ef56f6 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 4 Jun 2025 14:33:00 +0900 Subject: [PATCH 40/62] Revert "Alias value or join to take in old Ruby" This reverts commit 443ed0cf8540588b3e4e9bf8b52cb8834f13c8bc. --- test/uri/test_common.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index fef3f70..fef785a 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -74,9 +74,6 @@ def test_extract def test_ractor return unless defined?(Ractor) assert_ractor(<<~RUBY, require: 'uri') - class Ractor - alias value take unless method_defined? :value # compat with Ruby 3.4 and olders - end r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect } assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.value) RUBY From 6aef020b8ce6ee35747f37635797b22935cfd753 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 00:50:46 +0000 Subject: [PATCH 41/62] Bump step-security/harden-runner from 2.12.0 to 2.12.1 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.12.0 to 2.12.1. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/0634a2670c59f64b4a01f0f96f84700a4088b9f0...002fdce3c6a235733a90a27c80493a3241e56863) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.12.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index df5b8d5..9d20ae6 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 + uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 with: egress-policy: audit From d08f0efc2e539bc4c623157f28cc3a9851b06b8c Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 20 Jun 2025 13:42:45 +0900 Subject: [PATCH 42/62] Use GITHUB_TOKEN instead of admin credential --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 9d20ae6..860d90e 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -43,4 +43,4 @@ jobs: tag_name="$(git describe --tags --abbrev=0)" gh release create "${tag_name}" --verify-tag --generate-notes env: - GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d543c0dafa9221191a1844bb745f12faae297862 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 23 Jan 2025 21:19:20 +0900 Subject: [PATCH 43/62] Escape reserved characters in scheme name Fix #89 --- lib/uri/common.rb | 44 +++++++++++++++++++++++++++++++++-------- test/uri/test_common.rb | 21 ++++++++++---------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index db19e8e..fb9a318 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -92,6 +92,38 @@ def make_components_hash(klass, array_hash) end module Schemes # :nodoc: + class << self + ReservedChars = ".+-" + EscapedChars = "\uFE52\uFE62\uFE63" + + def escape(name) + unless name and name.ascii_only? + return nil + end + name.upcase.tr(ReservedChars, EscapedChars) + end + + def unescape(name) + name.tr(EscapedChars, ReservedChars).encode(Encoding::US_ASCII).upcase + end + + def find(name) + const_get(name, false) if name and const_defined?(name, false) + end + + def register(name, klass) + unless scheme = escape(name) + raise ArgumentError, "invalid characater as scheme - #{name}" + end + const_set(scheme, klass) + end + + def list + constants.map { |name| + [unescape(name.to_s), const_get(name)] + }.to_h + end + end end private_constant :Schemes @@ -104,7 +136,7 @@ module Schemes # :nodoc: # Note that after calling String#upcase on +scheme+, it must be a valid # constant name. def self.register_scheme(scheme, klass) - Schemes.const_set(scheme.to_s.upcase, klass) + Schemes.register(scheme, klass) end # Returns a hash of the defined schemes: @@ -122,9 +154,7 @@ def self.register_scheme(scheme, klass) # # Related: URI.register_scheme. def self.scheme_list - Schemes.constants.map { |name| - [name.to_s.upcase, Schemes.const_get(name)] - }.to_h + Schemes.list end INITIAL_SCHEMES = scheme_list @@ -148,12 +178,10 @@ def self.scheme_list # # => # # def self.for(scheme, *arguments, default: Generic) - const_name = scheme.to_s.upcase + const_name = Schemes.escape(scheme) uri_class = INITIAL_SCHEMES[const_name] - uri_class ||= if /\A[A-Z]\w*\z/.match?(const_name) && Schemes.const_defined?(const_name, false) - Schemes.const_get(const_name, false) - end + uri_class ||= Schemes.find(const_name) uri_class ||= default return uri_class.new(scheme, *arguments) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index fef785a..1291366 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -113,17 +113,18 @@ def test_register_scheme_lowercase def test_register_scheme_with_symbols # Valid schemes from https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml - some_uri_class = Class.new(URI::Generic) - assert_raise(NameError) { URI.register_scheme 'ms-search', some_uri_class } - assert_raise(NameError) { URI.register_scheme 'microsoft.windows.camera', some_uri_class } - assert_raise(NameError) { URI.register_scheme 'coaps+ws', some_uri_class } + list = [] + %w[ms-search microsoft.windows.camera coaps+ws].each {|name| + list << [name, URI.register_scheme(name, Class.new(URI::Generic))] + } - ms_search_class = Class.new(URI::Generic) - URI.register_scheme 'MS_SEARCH', ms_search_class - begin - assert_equal URI::Generic, URI.parse('ms-search://localhost').class - ensure - URI.const_get(:Schemes).send(:remove_const, :MS_SEARCH) + list.each do |scheme, uri_class| + assert_equal uri_class, URI.parse("#{scheme}://localhost").class + end + ensure + schemes = URI.const_get(:Schemes) + list.each do |scheme, | + schemes.send(:remove_const, schemes.escape(scheme)) end end From 5531d42375571a34eea0449e6c306c0b12a16be2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 23 Jan 2025 22:07:04 +0900 Subject: [PATCH 44/62] Use Lo category chars as escaped chars TruffleRuby does not allow Symbol categories as identifiers. --- lib/uri/common.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index fb9a318..ab02a64 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -94,7 +94,9 @@ def make_components_hash(klass, array_hash) module Schemes # :nodoc: class << self ReservedChars = ".+-" - EscapedChars = "\uFE52\uFE62\uFE63" + EscapedChars = "\u01C0\u01C1\u01C2" + # Use Lo category chars as escaped chars for TruffleRuby, which + # does not allow Symbol categories as identifiers. def escape(name) unless name and name.ascii_only? From b636e83d99d3e8d7237a964aea3a93fd710bb105 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 26 Jun 2025 10:33:05 +0900 Subject: [PATCH 45/62] Fix a typo Co-authored-by: Olle Jonsson --- lib/uri/common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index ab02a64..b1a47cf 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -115,7 +115,7 @@ def find(name) def register(name, klass) unless scheme = escape(name) - raise ArgumentError, "invalid characater as scheme - #{name}" + raise ArgumentError, "invalid character as scheme - #{name}" end const_set(scheme, klass) end From 30212d311ec9ebbc7191e38b1d508ea5684d6c39 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 25 Jan 2025 20:45:58 +0900 Subject: [PATCH 46/62] [DOC] State that uri library is needed to call Kernel#URI So that the example works as-is. --- lib/uri/common.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index b1a47cf..411a7e3 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -889,6 +889,7 @@ module Kernel # Returns a \URI object derived from the given +uri+, # which may be a \URI string or an existing \URI object: # + # require 'uri' # # Returns a new URI. # uri = URI('http://github.com/ruby/ruby') # # => # @@ -896,6 +897,8 @@ module Kernel # URI(uri) # # => # # + # You must require 'uri' to use this method. + # def URI(uri) if uri.is_a?(URI::Generic) uri From b69fe367ce914ef71200f339a9c6a8ec56e8933c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:13:35 +0000 Subject: [PATCH 47/62] Bump step-security/harden-runner from 2.12.1 to 2.12.2 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.12.1 to 2.12.2. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/002fdce3c6a235733a90a27c80493a3241e56863...6c439dc8bdf85cadbbce9ed30d1c7b959517bc49) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.12.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 860d90e..df1e741 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2 with: egress-policy: audit From d79b3f5b94758aec360c846b6f7fd002c3a4baef Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 8 Jul 2025 17:57:49 +0900 Subject: [PATCH 48/62] Prefer dedicated assertion methods --- test/uri/test_ftp.rb | 10 +++++----- test/uri/test_generic.rb | 40 ++++++++++++++++++++-------------------- test/uri/test_http.rb | 16 ++++++++-------- test/uri/test_parser.rb | 18 +++++++++--------- test/uri/test_ws.rb | 16 ++++++++-------- test/uri/test_wss.rb | 16 ++++++++-------- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/test/uri/test_ftp.rb b/test/uri/test_ftp.rb index f45bb06..3ad7864 100644 --- a/test/uri/test_ftp.rb +++ b/test/uri/test_ftp.rb @@ -33,11 +33,11 @@ def test_paths # If you think what's below is wrong, please read RubyForge bug 2055, # RFC 1738 section 3.2.2, and RFC 2396. u = URI.parse('ftp://ftp.example.com/foo/bar/file.ext') - assert(u.path == 'foo/bar/file.ext') + assert_equal('foo/bar/file.ext', u.path) u = URI.parse('ftp://ftp.example.com//foo/bar/file.ext') - assert(u.path == '/foo/bar/file.ext') + assert_equal('/foo/bar/file.ext', u.path) u = URI.parse('ftp://ftp.example.com/%2Ffoo/bar/file.ext') - assert(u.path == '/foo/bar/file.ext') + assert_equal('/foo/bar/file.ext', u.path) end def test_assemble @@ -45,8 +45,8 @@ def test_assemble # assuming everyone else has implemented RFC 2396. uri = URI::FTP.build(['user:password', 'ftp.example.com', nil, '/path/file.zip', 'i']) - assert(uri.to_s == - 'ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i') + assert_equal('ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i', + uri.to_s) end def test_select diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 1d5fbc7..b893f7e 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -240,9 +240,9 @@ def test_merge u = URI.parse('http://foo/bar/baz') assert_equal(nil, u.merge!("")) assert_equal(nil, u.merge!(u)) - assert(nil != u.merge!(".")) + refute_nil(u.merge!(".")) assert_equal('http://foo/bar/', u.to_s) - assert(nil != u.merge!("../baz")) + refute_nil(u.merge!("../baz")) assert_equal('http://foo/baz', u.to_s) url = URI.parse('http://a/b//c') + 'd//e' @@ -356,7 +356,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/g', url.to_s) url = @base_url.route_to('http://a/b/c/g') assert_kind_of(URI::Generic, url) - assert('./g' != url.to_s) # ok + refute_equal('./g', url.to_s) # ok assert_equal('g', url.to_s) # http://a/b/c/d;p?q @@ -375,7 +375,7 @@ def test_rfc3986_examples assert_equal('http://a/g', url.to_s) url = @base_url.route_to('http://a/g') assert_kind_of(URI::Generic, url) - assert('/g' != url.to_s) # ok + refute_equal('/g', url.to_s) # ok assert_equal('../../g', url.to_s) # http://a/b/c/d;p?q @@ -466,7 +466,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/', url.to_s) url = @base_url.route_to('http://a/b/c/') assert_kind_of(URI::Generic, url) - assert('.' != url.to_s) # ok + refute_equal('.', url.to_s) # ok assert_equal('./', url.to_s) # http://a/b/c/d;p?q @@ -485,7 +485,7 @@ def test_rfc3986_examples assert_equal('http://a/b/', url.to_s) url = @base_url.route_to('http://a/b/') assert_kind_of(URI::Generic, url) - assert('..' != url.to_s) # ok + refute_equal('..', url.to_s) # ok assert_equal('../', url.to_s) # http://a/b/c/d;p?q @@ -513,7 +513,7 @@ def test_rfc3986_examples assert_equal('http://a/', url.to_s) url = @base_url.route_to('http://a/') assert_kind_of(URI::Generic, url) - assert('../..' != url.to_s) # ok + refute_equal('../..', url.to_s) # ok assert_equal('../../', url.to_s) # http://a/b/c/d;p?q @@ -604,7 +604,7 @@ def test_rfc3986_examples assert_equal('http://a/g', url.to_s) url = @base_url.route_to('http://a/g') assert_kind_of(URI::Generic, url) - assert('../../../g' != url.to_s) # ok? yes, it confuses you + refute_equal('../../../g', url.to_s) # ok? yes, it confuses you assert_equal('../../g', url.to_s) # and it is clearly # http://a/b/c/d;p?q @@ -614,7 +614,7 @@ def test_rfc3986_examples assert_equal('http://a/g', url.to_s) url = @base_url.route_to('http://a/g') assert_kind_of(URI::Generic, url) - assert('../../../../g' != url.to_s) # ok? yes, it confuses you + refute_equal('../../../../g', url.to_s) # ok? yes, it confuses you assert_equal('../../g', url.to_s) # and it is clearly # http://a/b/c/d;p?q @@ -624,7 +624,7 @@ def test_rfc3986_examples assert_equal('http://a/b/g', url.to_s) url = @base_url.route_to('http://a/b/g') assert_kind_of(URI::Generic, url) - assert('./../g' != url.to_s) # ok + refute_equal('./../g', url.to_s) # ok assert_equal('../g', url.to_s) # http://a/b/c/d;p?q @@ -634,7 +634,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/g/', url.to_s) url = @base_url.route_to('http://a/b/c/g/') assert_kind_of(URI::Generic, url) - assert('./g/.' != url.to_s) # ok + refute_equal('./g/.', url.to_s) # ok assert_equal('g/', url.to_s) # http://a/b/c/d;p?q @@ -644,7 +644,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/g/h', url.to_s) url = @base_url.route_to('http://a/b/c/g/h') assert_kind_of(URI::Generic, url) - assert('g/./h' != url.to_s) # ok + refute_equal('g/./h', url.to_s) # ok assert_equal('g/h', url.to_s) # http://a/b/c/d;p?q @@ -654,7 +654,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/h', url.to_s) url = @base_url.route_to('http://a/b/c/h') assert_kind_of(URI::Generic, url) - assert('g/../h' != url.to_s) # ok + refute_equal('g/../h', url.to_s) # ok assert_equal('h', url.to_s) # http://a/b/c/d;p?q @@ -664,7 +664,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/g;x=1/y', url.to_s) url = @base_url.route_to('http://a/b/c/g;x=1/y') assert_kind_of(URI::Generic, url) - assert('g;x=1/./y' != url.to_s) # ok + refute_equal('g;x=1/./y', url.to_s) # ok assert_equal('g;x=1/y', url.to_s) # http://a/b/c/d;p?q @@ -674,7 +674,7 @@ def test_rfc3986_examples assert_equal('http://a/b/c/y', url.to_s) url = @base_url.route_to('http://a/b/c/y') assert_kind_of(URI::Generic, url) - assert('g;x=1/../y' != url.to_s) # ok + refute_equal('g;x=1/../y', url.to_s) # ok assert_equal('y', url.to_s) # http://a/b/c/d;p?q @@ -822,18 +822,18 @@ def test_hierarchical hierarchical = URI.parse('http://a.b.c/example') opaque = URI.parse('mailto:mduerst@ifi.unizh.ch') - assert hierarchical.hierarchical? - refute opaque.hierarchical? + assert_predicate hierarchical, :hierarchical? + refute_predicate opaque, :hierarchical? end def test_absolute abs_uri = URI.parse('http://a.b.c/') not_abs = URI.parse('a.b.c') - refute not_abs.absolute? + refute_predicate not_abs, :absolute? - assert abs_uri.absolute - assert abs_uri.absolute? + assert_predicate abs_uri, :absolute + assert_predicate abs_uri, :absolute? end def test_ipv6 diff --git a/test/uri/test_http.rb b/test/uri/test_http.rb index e937b1a..dc076ce 100644 --- a/test/uri/test_http.rb +++ b/test/uri/test_http.rb @@ -33,19 +33,19 @@ def test_normalize host = 'aBcD' u1 = URI.parse('http://' + host + '/eFg?HiJ') u2 = URI.parse('http://' + host.downcase + '/eFg?HiJ') - assert(u1.normalize.host == 'abcd') - assert(u1.normalize.path == u1.path) - assert(u1.normalize == u2.normalize) - assert(!u1.normalize.host.equal?(u1.host)) - assert( u2.normalize.host.equal?(u2.host)) + assert_equal('abcd', u1.normalize.host) + assert_equal(u1.path, u1.normalize.path) + assert_equal(u2.normalize, u1.normalize) + refute_same(u1.host, u1.normalize.host) + assert_same(u2.host, u2.normalize.host) assert_equal('http://abc/', URI.parse('http://abc').normalize.to_s) end def test_equal - assert(URI.parse('http://abc') == URI.parse('http://ABC')) - assert(URI.parse('http://abc/def') == URI.parse('http://ABC/def')) - assert(URI.parse('http://abc/def') != URI.parse('http://ABC/DEF')) + assert_equal(URI.parse('http://ABC'), URI.parse('http://abc')) + assert_equal(URI.parse('http://ABC/def'), URI.parse('http://abc/def')) + refute_equal(URI.parse('http://ABC/DEF'), URI.parse('http://abc/def')) end def test_request_uri diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index f455a5c..04c2cd3 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -20,17 +20,17 @@ def test_compare u2 = p.parse(url) u3 = p.parse(url) - assert(u0 == u1) - assert(u0.eql?(u1)) - assert(!u0.equal?(u1)) + assert_equal(u1, u0) + assert_send([u0, :eql?, u1]) + refute_same(u1, u0) - assert(u1 == u2) - assert(!u1.eql?(u2)) - assert(!u1.equal?(u2)) + assert_equal(u2, u1) + assert_not_send([u1, :eql?, u2]) + refute_same(u1, u2) - assert(u2 == u3) - assert(u2.eql?(u3)) - assert(!u2.equal?(u3)) + assert_equal(u3, u2) + assert_send([u2, :eql?, u3]) + refute_same(u3, u2) end def test_parse_rfc2396_parser diff --git a/test/uri/test_ws.rb b/test/uri/test_ws.rb index f3918f6..d63ebd4 100644 --- a/test/uri/test_ws.rb +++ b/test/uri/test_ws.rb @@ -31,19 +31,19 @@ def test_normalize host = 'aBcD' u1 = URI.parse('ws://' + host + '/eFg?HiJ') u2 = URI.parse('ws://' + host.downcase + '/eFg?HiJ') - assert(u1.normalize.host == 'abcd') - assert(u1.normalize.path == u1.path) - assert(u1.normalize == u2.normalize) - assert(!u1.normalize.host.equal?(u1.host)) - assert( u2.normalize.host.equal?(u2.host)) + assert_equal('abcd', u1.normalize.host) + assert_equal(u1.path, u1.normalize.path) + assert_equal(u2.normalize, u1.normalize) + refute_same(u1.host, u1.normalize.host) + assert_same(u2.host, u2.normalize.host) assert_equal('ws://abc/', URI.parse('ws://abc').normalize.to_s) end def test_equal - assert(URI.parse('ws://abc') == URI.parse('ws://ABC')) - assert(URI.parse('ws://abc/def') == URI.parse('ws://ABC/def')) - assert(URI.parse('ws://abc/def') != URI.parse('ws://ABC/DEF')) + assert_equal(URI.parse('ws://ABC'), URI.parse('ws://abc')) + assert_equal(URI.parse('ws://ABC/def'), URI.parse('ws://abc/def')) + refute_equal(URI.parse('ws://ABC/DEF'), URI.parse('ws://abc/def')) end def test_request_uri diff --git a/test/uri/test_wss.rb b/test/uri/test_wss.rb index 13a2583..cbef327 100644 --- a/test/uri/test_wss.rb +++ b/test/uri/test_wss.rb @@ -31,19 +31,19 @@ def test_normalize host = 'aBcD' u1 = URI.parse('wss://' + host + '/eFg?HiJ') u2 = URI.parse('wss://' + host.downcase + '/eFg?HiJ') - assert(u1.normalize.host == 'abcd') - assert(u1.normalize.path == u1.path) - assert(u1.normalize == u2.normalize) - assert(!u1.normalize.host.equal?(u1.host)) - assert( u2.normalize.host.equal?(u2.host)) + assert_equal('abcd', u1.normalize.host) + assert_equal(u1.path, u1.normalize.path) + assert_equal(u2.normalize, u1.normalize) + refute_same(u1.host, u1.normalize.host) + assert_same(u2.host, u2.normalize.host) assert_equal('wss://abc/', URI.parse('wss://abc').normalize.to_s) end def test_equal - assert(URI.parse('wss://abc') == URI.parse('wss://ABC')) - assert(URI.parse('wss://abc/def') == URI.parse('wss://ABC/def')) - assert(URI.parse('wss://abc/def') != URI.parse('wss://ABC/DEF')) + assert_equal(URI.parse('wss://ABC'), URI.parse('wss://abc')) + assert_equal(URI.parse('wss://ABC/def'), URI.parse('wss://abc/def')) + refute_equal(URI.parse('wss://ABC/DEF'), URI.parse('wss://abc/def')) end def test_request_uri From 6f44d3d40e5342041315f25b153ba8e4d5e0e745 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 12 Jul 2025 12:02:37 +0900 Subject: [PATCH 49/62] Fix the message for unexpected argument Use just `self` instead of `self.class`, in `URI::Generic.build`. Since this is a class method, `self.class` is always `Class` even in inherited sub classes, and does not have `#component` method. --- lib/uri/generic.rb | 4 ++-- test/uri/test_generic.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 07f329e..8cd280d 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -126,9 +126,9 @@ def self.build(args) end end else - component = self.class.component rescue ::URI::Generic::COMPONENT + component = self.component rescue ::URI::Generic::COMPONENT raise ArgumentError, - "expected Array of or Hash of components of #{self.class} (#{component.join(', ')})" + "expected Array of or Hash of components of #{self} (#{component.join(', ')})" end tmp << nil diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index b893f7e..0d29dd4 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -868,6 +868,19 @@ def test_build assert_equal("http://[::1]/bar/baz", u.to_s) assert_equal("[::1]", u.host) assert_equal("::1", u.hostname) + + assert_raise_with_message(ArgumentError, /URI::Generic/) { + URI::Generic.build(nil) + } + + c = Class.new(URI::Generic) do + def self.component; raise; end + end + expected = /\(#{URI::Generic::COMPONENT.join(', ')}\)/ + message = "fallback to URI::Generic::COMPONENT if component raised" + assert_raise_with_message(ArgumentError, expected, message) { + c.build(nil) + } end def test_build2 From 0c2b6468fa4f57288b1e4a462986985b6c942b22 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 8 Jul 2025 19:35:06 +0900 Subject: [PATCH 50/62] Make URI::regexp schemes case sensitive (#38) --- lib/uri/rfc2396_parser.rb | 2 +- test/uri/test_parser.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index 75a2d2d..c6096c4 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -263,7 +263,7 @@ def make_regexp(schemes = nil) unless schemes @regexp[:ABS_URI_REF] else - /(?=#{Regexp.union(*schemes)}:)#{@pattern[:X_ABS_URI]}/x + /(?=(?i:#{Regexp.union(*schemes).source}):)#{@pattern[:X_ABS_URI]}/x end end diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index 04c2cd3..c14824f 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -113,4 +113,12 @@ def test_rfc3986_port_check end end end + + def test_rfc2822_make_regexp + parser = URI::RFC2396_Parser.new + regexp = parser.make_regexp("HTTP") + assert_match(regexp, "HTTP://EXAMPLE.COM/") + assert_match(regexp, "http://example.com/") + refute_match(regexp, "https://example.com/") + end end From b1b5f9a476ecd16d82c4c9cde59b86d2efc582a2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 12 Jul 2025 15:53:33 +0900 Subject: [PATCH 51/62] More tests for `check_to` --- test/uri/test_mailto.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index e7c04ef..31adae2 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -165,6 +165,45 @@ def test_check_to assert_raise(URI::InvalidComponentError) do u.to = 'n.@invalid.email' end + + # Invalid host emails + assert_raise(URI::InvalidComponentError) do + u.to = 'a@.invalid.email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid.email.' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid..email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@-invalid.email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid-.email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid.-email' + end + + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid.email-' + end + + u.to = 'a@'+'invalid'.ljust(63, 'd')+'.email' + assert_raise(URI::InvalidComponentError) do + u.to = 'a@'+'invalid'.ljust(64, 'd')+'.email' + end + + u.to = 'a@invalid.'+'email'.rjust(63, 'e') + assert_raise(URI::InvalidComponentError) do + u.to = 'a@invalid.'+'email'.rjust(64, 'e') + end end def test_to_s From 32335923bf4dd20d11480b8d45cdd97800e964cb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 12 Jul 2025 15:54:38 +0900 Subject: [PATCH 52/62] Prohibit successive dots in email --- lib/uri/mailto.rb | 2 +- test/uri/test_mailto.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index a15d2f0..bd63aa0 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -52,7 +52,7 @@ class MailTo < Generic HEADER_REGEXP = /\A(?(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g)*\z/ # practical regexp for email address # https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address - EMAIL_REGEXP = /\A(?!\.)[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+(? Date: Sat, 12 Jul 2025 19:31:31 +0900 Subject: [PATCH 53/62] Improve performance of `URI::MailTo::EMAIL_REGEXP` Fix the performance regression at #172 for valid emails. ``` yml prelude: | require 'uri/mailto' n = 1000 re = URI::MailTo::EMAIL_REGEXP benchmark: n.t..t.: re.match?("n.t..t.@docomo.ne.jp") example: re.match?("example@example.info") ``` | |released| 788274b| c5974f0| this| |:--------|-------:|-------:|-------:|-------:| |n.t..t. | 3.795M| 4.864M| 4.993M| 8.739M| | | -| 1.28x| 1.32x| 2.30x| |example | 3.911M| 3.740M| 2.838M| 3.880M| | | 1.38x| 1.32x| -| 1.37x| --- lib/uri/mailto.rb | 6 +++++- test/uri/test_mailto.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index bd63aa0..f747b79 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -52,7 +52,11 @@ class MailTo < Generic HEADER_REGEXP = /\A(?(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g)*\z/ # practical regexp for email address # https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address - EMAIL_REGEXP = /\A(?!\.)(?!.*\.{2})[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+(?(n) {'a@invalid' + longlabel*(n*rate) + endlabel} + assert_linear_performance(1..10, pre: pre) do |to| + re =~ to or flunk + end + endlabel = '.' + 'email'.rjust(64, 'd') + assert_linear_performance(1..10, pre: pre) do |to| + re =~ to and flunk + end + end + def test_to_s u = URI::MailTo.build([nil, 'subject=Ruby']) From be35e0b4d8668352309da80d9cbc6cbb3d6e81f8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 12 Jul 2025 20:05:48 +0900 Subject: [PATCH 54/62] Test in exponential scale with rehearsal --- test/uri/test_mailto.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index 66f3edd..e5bed5b 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -213,15 +213,16 @@ def test_check_to def test_email_regexp re = URI::MailTo::EMAIL_REGEXP - rate = 1000 longlabel = '.' + 'invalid'.ljust(63, 'd') endlabel = '' - pre = ->(n) {'a@invalid' + longlabel*(n*rate) + endlabel} - assert_linear_performance(1..10, pre: pre) do |to| + seq = (1..5).map {|i| 5**i} + rehearsal = 100 + pre = ->(n) {'a@invalid' + longlabel*(n) + endlabel} + assert_linear_performance(seq, rehearsal: rehearsal, pre: pre) do |to| re =~ to or flunk end endlabel = '.' + 'email'.rjust(64, 'd') - assert_linear_performance(1..10, pre: pre) do |to| + assert_linear_performance(seq, rehearsal: rehearsal, pre: pre) do |to| re =~ to and flunk end end From fa49e5b8ae6078cad1f276c4edb33e4f23929bf4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 13 Jul 2025 13:18:15 +0900 Subject: [PATCH 55/62] Repeat matching to reduce deviations --- test/uri/test_mailto.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index e5bed5b..59bb5de 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -213,17 +213,18 @@ def test_check_to def test_email_regexp re = URI::MailTo::EMAIL_REGEXP + repeat = 10 longlabel = '.' + 'invalid'.ljust(63, 'd') endlabel = '' - seq = (1..5).map {|i| 5**i} - rehearsal = 100 + seq = (1..3).map {|i| 10**i} + rehearsal = 10 pre = ->(n) {'a@invalid' + longlabel*(n) + endlabel} assert_linear_performance(seq, rehearsal: rehearsal, pre: pre) do |to| - re =~ to or flunk + repeat.times {re =~ to or flunk} end endlabel = '.' + 'email'.rjust(64, 'd') assert_linear_performance(seq, rehearsal: rehearsal, pre: pre) do |to| - re =~ to and flunk + repeat.times {re =~ to and flunk} end end From 452d74390c9b5ebcbdb9fc9a8db0f2febb659ef6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 14 Jul 2025 13:14:53 +0900 Subject: [PATCH 56/62] [DOC] Fix references These are instance methods, not class methods. And `URI::Parser` was moved to URI::RFC2396_Parser at [r46491] [r46491]: ruby/ruby@bb83f32dc3e0424d25fa4e55d8ff32b061320e41 --- lib/uri/rfc2396_parser.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index c6096c4..8fdbf4b 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -108,12 +108,12 @@ def initialize(opts = {}) # The Hash of patterns. # - # See also URI::Parser.initialize_pattern. + # See also #initialize_pattern. attr_reader :pattern # The Hash of Regexp. # - # See also URI::Parser.initialize_regexp. + # See also #initialize_regexp. attr_reader :regexp # Returns a split URI against +regexp[:ABS_URI]+. @@ -244,7 +244,7 @@ def join(*uris) # If no +block+ given, then returns the result, # else it calls +block+ for each element in result. # - # See also URI::Parser.make_regexp. + # See also #make_regexp. # def extract(str, schemes = nil) if block_given? From 372fbb455d6c21370945d1e77472984d2be2bdae Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 14 Jul 2025 13:23:54 +0900 Subject: [PATCH 57/62] [DOC] Document private visibility too For the references to URI::RFC2396_Parser private methods. --- .rdoc_options | 1 + lib/uri/common.rb | 6 ++++++ lib/uri/rfc2396_parser.rb | 2 ++ 3 files changed, 9 insertions(+) diff --git a/.rdoc_options b/.rdoc_options index b1f9cda..cd5e496 100644 --- a/.rdoc_options +++ b/.rdoc_options @@ -2,3 +2,4 @@ main_page: README.md op_dir: _site warn_missing_rdoc_ref: true title: URI Documentation +visibility: :private diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 411a7e3..baa0fd2 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -159,9 +159,11 @@ def self.scheme_list Schemes.list end + # :stopdoc: INITIAL_SCHEMES = scheme_list private_constant :INITIAL_SCHEMES Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor) + # :startdoc: # Returns a new object constructed from the given +scheme+, +arguments+, # and +default+: @@ -437,6 +439,8 @@ def self.decode_uri_component(str, enc=Encoding::UTF_8) _decode_uri_component(/%\h\h/, str, enc) end + # Returns a string derived from the given string +str+ with + # URI-encoded characters matching +regexp+ according to +table+. def self._encode_uri_component(regexp, table, str, enc) str = str.to_s.dup if str.encoding != Encoding::ASCII_8BIT @@ -451,6 +455,8 @@ def self._encode_uri_component(regexp, table, str, enc) end private_class_method :_encode_uri_component + # Returns a string decoding characters matching +regexp+ from the + # given \URL-encoded string +str+. def self._decode_uri_component(regexp, str, enc) raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/.match?(str) str.b.gsub(regexp, TBLDECWWWCOMP_).force_encoding(enc) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index 8fdbf4b..f0d544e 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -524,6 +524,8 @@ def initialize_regexp(pattern) ret end + # Returns +uri+ as-is if it is URI, or convert it to URI if it is + # a String. def convert_to_uri(uri) if uri.is_a?(URI::Generic) uri From d2a79c63430a8374b9d9ee1486027caadce35418 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 14 Jul 2025 13:54:07 +0900 Subject: [PATCH 58/62] [DOC] Update old use of `URI::Parser` --- lib/uri/generic.rb | 18 +++++++++--------- lib/uri/rfc2396_parser.rb | 7 +++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 8cd280d..d811c5b 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -284,7 +284,7 @@ def registry # :nodoc: # Returns the parser to be used. # - # Unless a URI::Parser is defined, DEFAULT_PARSER is used. + # Unless the +parser+ is defined, DEFAULT_PARSER is used. # def parser if !defined?(@parser) || !@parser @@ -315,7 +315,7 @@ def component end # - # Checks the scheme +v+ component against the URI::Parser Regexp for :SCHEME. + # Checks the scheme +v+ component against the +parser+ Regexp for :SCHEME. # def check_scheme(v) if v && parser.regexp[:SCHEME] !~ v @@ -385,7 +385,7 @@ def check_userinfo(user, password = nil) # # Checks the user +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp for :USERINFO. + # and against the +parser+ Regexp for :USERINFO. # # Can not have a registry or opaque component defined, # with a user component defined. @@ -409,7 +409,7 @@ def check_user(v) # # Checks the password +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp for :USERINFO. + # and against the +parser+ Regexp for :USERINFO. # # Can not have a registry or opaque component defined, # with a user component defined. @@ -586,7 +586,7 @@ def decoded_password # # Checks the host +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp for :HOST. + # and against the +parser+ Regexp for :HOST. # # Can not have a registry or opaque component defined, # with a host component defined. @@ -675,7 +675,7 @@ def hostname=(v) # # Checks the port +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp for :PORT. + # and against the +parser+ Regexp for :PORT. # # Can not have a registry or opaque component defined, # with a port component defined. @@ -748,7 +748,7 @@ def registry=(v) # :nodoc: # # Checks the path +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp + # and against the +parser+ Regexp # for :ABS_PATH and :REL_PATH. # # Can not have a opaque component defined, @@ -853,7 +853,7 @@ def query=(v) # # Checks the opaque +v+ component for RFC2396 compliance and - # against the URI::Parser Regexp for :OPAQUE. + # against the +parser+ Regexp for :OPAQUE. # # Can not have a host, port, user, or path component defined, # with an opaque component defined. @@ -905,7 +905,7 @@ def opaque=(v) end # - # Checks the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT. + # Checks the fragment +v+ component against the +parser+ Regexp for :FRAGMENT. # # # == Args diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index f0d544e..cefd126 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -67,7 +67,7 @@ class RFC2396_Parser # # == Synopsis # - # URI::Parser.new([opts]) + # URI::RFC2396_Parser.new([opts]) # # == Args # @@ -86,7 +86,7 @@ class RFC2396_Parser # # == Examples # - # p = URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})") + # p = URI::RFC2396_Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})") # u = p.parse("http://example.jp/%uABCD") #=> # # URI.parse(u.to_s) #=> raises URI::InvalidURIError # @@ -202,8 +202,7 @@ def split(uri) # # == Usage # - # p = URI::Parser.new - # p.parse("ldap://ldap.example.com/dc=example?user=john") + # URI::RFC2396_PARSER.parse("ldap://ldap.example.com/dc=example?user=john") # #=> # # def parse(uri) From 7c13b16a35a61ea53d869dacec164a1c6ffe6f69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 00:45:22 +0000 Subject: [PATCH 59/62] Bump step-security/harden-runner from 2.12.2 to 2.13.0 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.12.2 to 2.13.0. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/6c439dc8bdf85cadbbce9ed30d1c7b959517bc49...ec9f2d5744a09debf3a187a3f4f675c53b671911) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.13.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index df1e741..d4f354e 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2 + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 with: egress-policy: audit From 49fc1e7040130838812ab50422292b98e340e221 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 00:49:01 +0000 Subject: [PATCH 60/62] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/gh-pages.yml | 2 +- .github/workflows/push_gem.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index e7ee429..1989641 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Setup Ruby uses: ruby/setup-ruby@32110d4e311bd8996b2a82bf2a43b714ccc91777 # v1.221.0 with: diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index d4f354e..b7d2984 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -27,7 +27,7 @@ jobs: with: egress-policy: audit - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v4.1.4 - name: Set up Ruby uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee9b2a5..ba860e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: os: macos-latest runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: From 0b8f44009509061440c1be2f537fdaf619bed87b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 00:26:44 +0000 Subject: [PATCH 61/62] Bump actions/upload-pages-artifact from 3 to 4 Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-pages-artifact/releases) - [Commits](https://github.com/actions/upload-pages-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-pages-artifact dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 1989641..585eb8a 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -32,7 +32,7 @@ jobs: # Outputs to the './_site' directory by default run: rake rdoc - name: Upload artifact - uses: actions/upload-pages-artifact@v3 + uses: actions/upload-pages-artifact@v4 deploy: environment: From 5bf1ab9de6ca323e4ba07e3a2f619c5d970299b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:02:02 +0000 Subject: [PATCH 62/62] Bump step-security/harden-runner from 2.13.0 to 2.13.1 Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.13.0 to 2.13.1. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/ec9f2d5744a09debf3a187a3f4f675c53b671911...f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.13.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/push_gem.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index b7d2984..c6b1e47 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 + uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 with: egress-policy: audit