diff --git a/lib/uri/common.rb b/lib/uri/common.rb index a4ed70f9a3..98cb18ec0d 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -27,8 +27,10 @@ module URI const_set("Parser", parser.class) remove_const(:REGEXP) if defined?(REGEXP) + remove_const(:PATTERN) if defined?(PATTERN) 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) diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 8d0a206c86..aa9c6898ed 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -12,17 +12,21 @@ class URI::TestCommon < Test::Unit::TestCase def test_parser_switch assert_equal(URI::Parser, URI::RFC3986_Parser) - refute defined?(::URI::REGEXP) + refute defined?(URI::REGEXP) + refute defined?(URI::PATTERN) URI.parser = URI::RFC2396_PARSER assert_equal(URI::Parser, URI::RFC2396_Parser) assert defined?(URI::REGEXP) + assert defined?(URI::PATTERN) + assert defined?(URI::PATTERN::ESCAPED) URI.parser = URI::RFC3986_PARSER assert_equal(URI::Parser, URI::RFC3986_Parser) refute defined?(URI::REGEXP) + refute defined?(URI::PATTERN) ensure URI.parser = URI::RFC3986_PARSER end