Skip to content

Commit

Permalink
Fallback missing constants with RFC3986_PARSER (#113)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
hsbt and nobu authored Aug 6, 2024
1 parent 4b723f5 commit c2fdec0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def self.parser=(parser = RFC3986_PARSER)
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 = {}
Expand Down
9 changes: 9 additions & 0 deletions test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def setup
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)
Expand Down

0 comments on commit c2fdec0

Please sign in to comment.