Skip to content

Commit

Permalink
Added more fallback constants like URI::PARTTERN and URI::REGEXP
Browse files Browse the repository at this point in the history
Fixed #125
  • Loading branch information
hsbt committed Nov 8, 2024
1 parent af8d9d6 commit 1f3d3df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f3d3df

Please sign in to comment.