Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2fdec0

Browse files
hsbtnobu
andauthored
Fallback missing constants with RFC3986_PARSER (#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]> --------- Co-authored-by: Nobuyoshi Nakada <[email protected]>
1 parent 4b723f5 commit c2fdec0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/uri/common.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ def self.parser=(parser = RFC3986_PARSER)
4545
end
4646
self.parser = RFC3986_PARSER
4747

48+
def self.const_missing(const)
49+
if value = RFC2396_PARSER.regexp[const]
50+
warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE
51+
value
52+
else
53+
super
54+
end
55+
end
56+
4857
module Util # :nodoc:
4958
def make_components_hash(klass, array_hash)
5059
tmp = {}

test/uri/test_common.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ def setup
1010
def teardown
1111
end
1212

13+
def test_fallback_constants
14+
orig_verbose = $VERBOSE
15+
$VERBOSE = nil
16+
assert URI::ABS_URI
17+
assert_raise(NameError) { URI::FOO }
18+
ensure
19+
$VERBOSE = orig_verbose
20+
end
21+
1322
def test_parser_switch
1423
assert_equal(URI::Parser, URI::RFC3986_Parser)
1524
refute defined?(URI::REGEXP)

0 commit comments

Comments
 (0)