From ee9a38701a3d49b7d56f7e7a1fd846333186d748 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 12:01:06 +0900 Subject: [PATCH 1/2] Restore constants like URI::REGEXP::PATTERN::IPV6ADDR --- lib/uri/rfc2396_parser.rb | 7 +++++++ test/uri/test_common.rb | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index a56ca34..c112b1b 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -536,4 +536,11 @@ def convert_to_uri(uri) end end # class Parser + + # Backward compatibility for URI::REGEXP::PATTERN::* + RFC2396_Parser.new.pattern.each_pair do |sym, str| + unless RFC2396_REGEXP::PATTERN.const_defined?(sym) + RFC2396_REGEXP::PATTERN.const_set(sym, str) + end + end end # module URI diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 176efb8..b1e3b2b 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -10,6 +10,10 @@ def setup def teardown end + class Foo + include URI::REGEXP::PATTERN + end + def test_fallback_constants orig_verbose = $VERBOSE $VERBOSE = nil @@ -19,6 +23,8 @@ def test_fallback_constants 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 + assert_equal URI::REGEXP::PATTERN, URI::RFC2396_REGEXP::PATTERN + assert_equal Foo::IPV4ADDR, URI::RFC2396_REGEXP::PATTERN::IPV4ADDR ensure $VERBOSE = orig_verbose end From 60a8bc15759065762fda95e83f383747904089a8 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 13 Nov 2024 12:02:46 +0900 Subject: [PATCH 2/2] Removed duplicated declare step for constants under the URI::RFC2396_REGEXP::PATTERN --- lib/uri/common.rb | 5 ----- test/uri/test_common.rb | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index fe8475f..f13ff1a 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -31,11 +31,6 @@ def self.parser=(parser = RFC3986_PARSER) if Parser == RFC2396_Parser const_set("REGEXP", URI::RFC2396_REGEXP) const_set("PATTERN", URI::RFC2396_REGEXP::PATTERN) - Parser.new.pattern.each_pair do |sym, str| - unless REGEXP::PATTERN.const_defined?(sym) - REGEXP::PATTERN.const_set(sym, str) - end - end end Parser.new.regexp.each_pair do |sym, str| diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index b1e3b2b..e96f819 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -40,6 +40,7 @@ def test_parser_switch assert defined?(URI::REGEXP) assert defined?(URI::PATTERN) assert defined?(URI::PATTERN::ESCAPED) + assert defined?(URI::REGEXP::PATTERN::IPV6ADDR) URI.parser = URI::RFC3986_PARSER