summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2024-11-08 15:05:58 +0900
committergit <[email protected]>2024-11-08 06:06:30 +0000
commitd7c65398e0a3d4f1e1201effc96929c7f102e37b (patch)
tree4075e9f7a1db2dd877ae96415e4db5aa683426a9
parent85868388d5bc51b1856af05155c043e47e803bb2 (diff)
[ruby/uri] Added more fallback constants like URI::PARTTERN and URI::REGEXP
Fixed https://github.com/ruby/uri/issues/125 https://github.com/ruby/uri/commit/1f3d3df02a
-rw-r--r--lib/uri/common.rb8
-rw-r--r--test/uri/test_common.rb6
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 904df10663..621353093d 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -46,9 +46,15 @@ module URI
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 bccdeafeaf..176efb80b9 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -13,8 +13,12 @@ class URI::TestCommon < Test::Unit::TestCase
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