Skip to content

Commit d629c8c

Browse files
authored
Merge pull request #161 from y-yagi/fix_changing_parser
Switch a parsing behavior completely when switching a parser
2 parents fec6733 + aded210 commit d629c8c

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/uri/common.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def self.parser=(parser = RFC3986_PARSER)
3030
remove_const(:Parser) if defined?(::URI::Parser)
3131
const_set("Parser", parser.class)
3232

33+
remove_const(:PARSER) if defined?(::URI::PARSER)
34+
const_set("PARSER", parser)
35+
3336
remove_const(:REGEXP) if defined?(::URI::REGEXP)
3437
remove_const(:PATTERN) if defined?(::URI::PATTERN)
3538
if Parser == RFC2396_Parser
@@ -227,7 +230,7 @@ class BadURIError < Error; end
227230
# ["fragment", "top"]]
228231
#
229232
def self.split(uri)
230-
DEFAULT_PARSER.split(uri)
233+
PARSER.split(uri)
231234
end
232235

233236
# Returns a new \URI object constructed from the given string +uri+:
@@ -241,7 +244,7 @@ def self.split(uri)
241244
# if it may contain invalid URI characters.
242245
#
243246
def self.parse(uri)
244-
DEFAULT_PARSER.parse(uri)
247+
PARSER.parse(uri)
245248
end
246249

247250
# Merges the given URI strings +str+
@@ -297,7 +300,7 @@ def self.join(*str)
297300
#
298301
def self.extract(str, schemes = nil, &block) # :nodoc:
299302
warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE
300-
DEFAULT_PARSER.extract(str, schemes, &block)
303+
PARSER.extract(str, schemes, &block)
301304
end
302305

303306
#
@@ -334,7 +337,7 @@ def self.extract(str, schemes = nil, &block) # :nodoc:
334337
#
335338
def self.regexp(schemes = nil)# :nodoc:
336339
warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE
337-
DEFAULT_PARSER.make_regexp(schemes)
340+
PARSER.make_regexp(schemes)
338341
end
339342

340343
TBLENCWWWCOMP_ = {} # :nodoc:

test/uri/test_common.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ def test_fallback_constants
3131

3232
def test_parser_switch
3333
assert_equal(URI::Parser, URI::RFC3986_Parser)
34+
assert_equal(URI::PARSER, URI::RFC3986_PARSER)
3435
refute defined?(URI::REGEXP)
3536
refute defined?(URI::PATTERN)
3637

3738
URI.parser = URI::RFC2396_PARSER
3839

3940
assert_equal(URI::Parser, URI::RFC2396_Parser)
41+
assert_equal(URI::PARSER, URI::RFC2396_PARSER)
4042
assert defined?(URI::REGEXP)
4143
assert defined?(URI::PATTERN)
4244
assert defined?(URI::PATTERN::ESCAPED)
@@ -45,6 +47,7 @@ def test_parser_switch
4547
URI.parser = URI::RFC3986_PARSER
4648

4749
assert_equal(URI::Parser, URI::RFC3986_Parser)
50+
assert_equal(URI::PARSER, URI::RFC3986_PARSER)
4851
refute defined?(URI::REGEXP)
4952
refute defined?(URI::PATTERN)
5053
ensure

0 commit comments

Comments
 (0)