Skip to content

Commit 1f3d3df

Browse files
committed
Added more fallback constants like URI::PARTTERN and URI::REGEXP
Fixed #125
1 parent af8d9d6 commit 1f3d3df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/uri/common.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ def self.parser=(parser = RFC3986_PARSER)
4646
self.parser = RFC3986_PARSER
4747

4848
def self.const_missing(const)
49-
if value = RFC2396_PARSER.regexp[const]
49+
if const == :REGEXP
50+
warn "URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.", uplevel: 1 if $VERBOSE
51+
URI::RFC2396_REGEXP
52+
elsif value = RFC2396_PARSER.regexp[const]
5053
warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE
5154
value
55+
elsif value = RFC2396_Parser.const_get(const)
56+
warn "URI::#{const} is obsolete. Use RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE
57+
value
5258
else
5359
super
5460
end

test/uri/test_common.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ def teardown
1313
def test_fallback_constants
1414
orig_verbose = $VERBOSE
1515
$VERBOSE = nil
16-
assert URI::ABS_URI
16+
1717
assert_raise(NameError) { URI::FOO }
18+
19+
assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI]
20+
assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN
21+
assert_equal URI::REGEXP, URI::RFC2396_REGEXP
1822
ensure
1923
$VERBOSE = orig_verbose
2024
end

0 commit comments

Comments
 (0)