[ruby/uri] Fallback missing constants with RFC3986_PARSER

(https://github.com/ruby/uri/pull/113)

* Fallback missing constants with RFC3986_PARSER

* raise missing constant

* Update test/uri/test_common.rb

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

* Update lib/uri/common.rb

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

* Update lib/uri/common.rb

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

---------

https://github.com/ruby/uri/commit/c2fdec079a

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
Hiroshi SHIBATA 2024-08-06 17:09:47 +08:00 committed by git
parent 24d46a6781
commit 267da552a1
2 changed files with 18 additions and 0 deletions

View File

@ -45,6 +45,15 @@ module URI
end end
self.parser = RFC3986_PARSER 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: module Util # :nodoc:
def make_components_hash(klass, array_hash) def make_components_hash(klass, array_hash)
tmp = {} tmp = {}

View File

@ -10,6 +10,15 @@ class URI::TestCommon < Test::Unit::TestCase
def teardown def teardown
end 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 def test_parser_switch
assert_equal(URI::Parser, URI::RFC3986_Parser) assert_equal(URI::Parser, URI::RFC3986_Parser)
refute defined?(URI::REGEXP) refute defined?(URI::REGEXP)