Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def self.parser=(parser = RFC3986_PARSER)
remove_const(:Parser) if defined?(::URI::Parser)
const_set("Parser", parser.class)

remove_const(:PARSER) if defined?(::URI::PARSER)
const_set("PARSER", parser)

remove_const(:REGEXP) if defined?(::URI::REGEXP)
remove_const(:PATTERN) if defined?(::URI::PATTERN)
if Parser == RFC2396_Parser
Expand Down Expand Up @@ -195,7 +198,7 @@ class BadURIError < Error; end
# ["fragment", "top"]]
#
def self.split(uri)
DEFAULT_PARSER.split(uri)
PARSER.split(uri)
end

# Returns a new \URI object constructed from the given string +uri+:
Expand All @@ -209,7 +212,7 @@ def self.split(uri)
# if it may contain invalid URI characters.
#
def self.parse(uri)
DEFAULT_PARSER.parse(uri)
PARSER.parse(uri)
end

# Merges the given URI strings +str+
Expand Down Expand Up @@ -265,7 +268,7 @@ def self.join(*str)
#
def self.extract(str, schemes = nil, &block) # :nodoc:
warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.extract(str, schemes, &block)
PARSER.extract(str, schemes, &block)
end

#
Expand Down Expand Up @@ -302,7 +305,7 @@ def self.extract(str, schemes = nil, &block) # :nodoc:
#
def self.regexp(schemes = nil)# :nodoc:
warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.make_regexp(schemes)
PARSER.make_regexp(schemes)
end

TBLENCWWWCOMP_ = {} # :nodoc:
Expand Down
3 changes: 3 additions & 0 deletions test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ def test_fallback_constants

def test_parser_switch
assert_equal(URI::Parser, URI::RFC3986_Parser)
assert_equal(URI::PARSER, URI::RFC3986_PARSER)
refute defined?(URI::REGEXP)
refute defined?(URI::PATTERN)

URI.parser = URI::RFC2396_PARSER

assert_equal(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)
Expand All @@ -45,6 +47,7 @@ def test_parser_switch
URI.parser = URI::RFC3986_PARSER

assert_equal(URI::Parser, URI::RFC3986_Parser)
assert_equal(URI::PARSER, URI::RFC3986_PARSER)
refute defined?(URI::REGEXP)
refute defined?(URI::PATTERN)
ensure
Expand Down