From f5fc97c72f624e1637e34f1273a8be1f5e30f2a5 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 6 Aug 2024 15:38:10 +0900 Subject: [PATCH 1/5] Fallback missing constants with RFC3986_PARSER --- lib/uri/common.rb | 7 +++++++ test/uri/test_common.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 4e8210d..be92694 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -45,6 +45,13 @@ def self.parser=(parser = RFC3986_PARSER) end self.parser = RFC3986_PARSER + def self.const_missing(const) + if RFC2396_PARSER.regexp[const] + warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE + RFC2396_PARSER.regexp[const] + end + end + module Util # :nodoc: def make_components_hash(klass, array_hash) tmp = {} diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index aa9c689..a42e4df 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -10,6 +10,13 @@ def setup def teardown end + def test_fallback_constants + orig_verbose = $VERBOSE + $VERBOSE = nil + assert URI::ABS_URI + $VERBOSE = orig_verbose + end + def test_parser_switch assert_equal(URI::Parser, URI::RFC3986_Parser) refute defined?(URI::REGEXP) From e3e8549e11717280a965309593070f5ca21c0984 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 6 Aug 2024 16:02:13 +0900 Subject: [PATCH 2/5] raise missing constant --- lib/uri/common.rb | 2 ++ test/uri/test_common.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index be92694..78d3be1 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -49,6 +49,8 @@ def self.const_missing(const) if RFC2396_PARSER.regexp[const] warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE RFC2396_PARSER.regexp[const] + else + raise NameError, "uninitialized constant URI::#{const}" end end diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index a42e4df..07b738a 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -14,6 +14,7 @@ def test_fallback_constants orig_verbose = $VERBOSE $VERBOSE = nil assert URI::ABS_URI + assert_raise(NameError) { URI::FOO } $VERBOSE = orig_verbose end From 884df86e836dc82404fefdf05263da4a5c178dc4 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 6 Aug 2024 18:06:08 +0900 Subject: [PATCH 3/5] Update test/uri/test_common.rb Co-authored-by: Nobuyoshi Nakada --- test/uri/test_common.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 07b738a..bccdeaf 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -15,6 +15,7 @@ def test_fallback_constants $VERBOSE = nil assert URI::ABS_URI assert_raise(NameError) { URI::FOO } + ensure $VERBOSE = orig_verbose end From b82842ee9d40e40e01dde24f4a0c501257957602 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 6 Aug 2024 18:06:14 +0900 Subject: [PATCH 4/5] Update lib/uri/common.rb Co-authored-by: Nobuyoshi Nakada --- 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 78d3be1..8542c51 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -50,7 +50,7 @@ def self.const_missing(const) warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE RFC2396_PARSER.regexp[const] else - raise NameError, "uninitialized constant URI::#{const}" + super end end From 238afb9a752e3691f8f8c30bbd10e67c26778374 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 6 Aug 2024 18:06:20 +0900 Subject: [PATCH 5/5] Update lib/uri/common.rb Co-authored-by: Nobuyoshi Nakada --- 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 8542c51..cf93fb1 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -46,9 +46,9 @@ def self.parser=(parser = RFC3986_PARSER) self.parser = RFC3986_PARSER def self.const_missing(const) - if RFC2396_PARSER.regexp[const] + if value = RFC2396_PARSER.regexp[const] warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE - RFC2396_PARSER.regexp[const] + value else super end