Skip to content

Commit 6f616d9

Browse files
committed
Added test for constant definition and remove URI::REGEXP when using RFC3986_PARSER
1 parent 984145c commit 6f616d9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/uri/common.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ def self.parser=(parser = RFC3986_PARSER)
2626
remove_const(:Parser) if defined?(Parser)
2727
const_set("Parser", parser.class)
2828

29+
remove_const(:REGEXP) if defined?(REGEXP)
2930
if Parser == RFC2396_Parser
30-
remove_const(:REGEXP) if defined?(REGEXP)
3131
const_set("REGEXP", URI::RFC2396_REGEXP)
3232
Parser.new.pattern.each_pair do |sym, str|
3333
unless REGEXP::PATTERN.const_defined?(sym)
3434
REGEXP::PATTERN.const_set(sym, str)
3535
end
3636
end
3737
end
38+
3839
Parser.new.regexp.each_pair do |sym, str|
3940
remove_const(sym) if const_defined?(sym)
4041
const_set(sym, str)

test/uri/test_common.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ def setup
1010
def teardown
1111
end
1212

13+
def test_parser_switch
14+
assert_equal(URI::Parser, URI::RFC3986_Parser)
15+
refute defined?(::URI::REGEXP)
16+
17+
URI.parser = URI::RFC2396_PARSER
18+
19+
assert_equal(URI::Parser, URI::RFC2396_Parser)
20+
assert defined?(URI::REGEXP)
21+
22+
URI.parser = URI::RFC3986_PARSER
23+
24+
assert_equal(URI::Parser, URI::RFC3986_Parser)
25+
refute defined?(URI::REGEXP)
26+
ensure
27+
URI.parser = URI::RFC3986_PARSER
28+
end
29+
1330
def test_extract
1431
EnvUtil.suppress_warning do
1532
assert_equal(['http://example.com'],

0 commit comments

Comments
 (0)