Skip to content

Commit 45fbdcc

Browse files
committed
Added URI.parser= method for switch back to RFC2396_Parser
1 parent ab8ee6f commit 45fbdcc

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lib/uri/common.rb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,35 @@
1313
require_relative "rfc3986_parser"
1414

1515
module URI
16-
include RFC2396_REGEXP
16+
RFC2396_PARSER = RFC2396_Parser.new
17+
Ractor.make_shareable(RFC2396_PARSER) if defined?(Ractor)
1718

18-
REGEXP = RFC2396_REGEXP
19-
Parser = RFC2396_Parser
2019
RFC3986_PARSER = RFC3986_Parser.new
2120
Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
2221

23-
# URI::Parser.new
24-
DEFAULT_PARSER = Parser.new
25-
DEFAULT_PARSER.pattern.each_pair do |sym, str|
26-
unless REGEXP::PATTERN.const_defined?(sym)
27-
REGEXP::PATTERN.const_set(sym, str)
22+
def self.parser=(parser = RFC3986_PARSER)
23+
remove_const(:Parser) if defined?(Parser)
24+
remove_const(:DEFAULT_PARSER) if defined?(DEFAULT_PARSER)
25+
remove_const(:REGEXP) if defined?(REGEXP)
26+
27+
# URI::Parser.new
28+
const_set("Parser", parser.class)
29+
const_set("DEFAULT_PARSER", parser)
30+
if DEFAULT_PARSER.class == RFC2396_Parser
31+
const_set("REGEXP", RFC2396_PARSER::REGEXP)
32+
DEFAULT_PARSER.pattern.each_pair do |sym, str|
33+
unless REGEXP::PATTERN.const_defined?(sym)
34+
REGEXP::PATTERN.const_set(sym, str)
35+
end
36+
end
2837
end
38+
DEFAULT_PARSER.regexp.each_pair do |sym, str|
39+
remove_const(sym) if const_defined?(sym)
40+
const_set(sym, str)
41+
end
42+
Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
2943
end
30-
DEFAULT_PARSER.regexp.each_pair do |sym, str|
31-
const_set(sym, str)
32-
end
33-
Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
44+
self.parser = RFC3986_PARSER
3445

3546
module Util # :nodoc:
3647
def make_components_hash(klass, array_hash)

0 commit comments

Comments
 (0)