summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2024-08-06 17:09:47 +0800
committergit <[email protected]>2024-08-06 09:09:52 +0000
commit267da552a1085e69fabe9aadb2007843c5eb1b31 (patch)
tree543b69445dfa0b4b2f61c185a1c79849d8e28540
parent24d46a6781231c54d6b5fc0a20a24cd65a902ad4 (diff)
[ruby/uri] Fallback missing constants with RFC3986_PARSER
(https://github.com/ruby/uri/pull/113) * Fallback missing constants with RFC3986_PARSER * raise missing constant * Update test/uri/test_common.rb Co-authored-by: Nobuyoshi Nakada <[email protected]> * Update lib/uri/common.rb Co-authored-by: Nobuyoshi Nakada <[email protected]> * Update lib/uri/common.rb Co-authored-by: Nobuyoshi Nakada <[email protected]> --------- https://github.com/ruby/uri/commit/c2fdec079a Co-authored-by: Nobuyoshi Nakada <[email protected]>
-rw-r--r--lib/uri/common.rb9
-rw-r--r--test/uri/test_common.rb9
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index e31e0abcc0..904df10663 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -45,6 +45,15 @@ module URI
end
self.parser = RFC3986_PARSER
+ def self.const_missing(const)
+ if value = RFC2396_PARSER.regexp[const]
+ warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE
+ value
+ else
+ super
+ 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 aa9c6898ed..bccdeafeaf 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -10,6 +10,15 @@ class URI::TestCommon < Test::Unit::TestCase
def teardown
end
+ def test_fallback_constants
+ orig_verbose = $VERBOSE
+ $VERBOSE = nil
+ assert URI::ABS_URI
+ assert_raise(NameError) { URI::FOO }
+ ensure
+ $VERBOSE = orig_verbose
+ end
+
def test_parser_switch
assert_equal(URI::Parser, URI::RFC3986_Parser)
refute defined?(URI::REGEXP)