Skip to content

Commit

Permalink
Also support URI::PATTERN with switch-back
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 18, 2024
1 parent 6f616d9 commit 823697e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def self.parser=(parser = RFC3986_PARSER)
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)
Expand Down
6 changes: 5 additions & 1 deletion test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ def teardown

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
Expand Down

0 comments on commit 823697e

Please sign in to comment.