From 08e449d89baf1aeee87f084e1cd55bfe3b9cc46a Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 17 Jul 2024 18:53:54 +0900 Subject: [ruby/uri] Added URI.parser= method for switch back to RFC2396_Parser https://github.com/ruby/uri/commit/d7dc19ad3f --- lib/uri/common.rb | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/uri/common.rb b/lib/uri/common.rb index dce09fbc1e..4515a77af6 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -13,24 +13,34 @@ require_relative "rfc2396_parser" require_relative "rfc3986_parser" module URI - include RFC2396_REGEXP + RFC2396_PARSER = RFC2396_Parser.new + Ractor.make_shareable(RFC2396_PARSER) if defined?(Ractor) - REGEXP = RFC2396_REGEXP - Parser = RFC2396_Parser RFC3986_PARSER = RFC3986_Parser.new Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor) - # URI::Parser.new - DEFAULT_PARSER = Parser.new - DEFAULT_PARSER.pattern.each_pair do |sym, str| - unless REGEXP::PATTERN.const_defined?(sym) - REGEXP::PATTERN.const_set(sym, str) + DEFAULT_PARSER = RFC3986_PARSER + Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor) + + def self.parser=(parser = RFC3986_PARSER) + remove_const(:Parser) if defined?(Parser) + const_set("Parser", parser.class) + + if Parser == RFC2396_Parser + remove_const(:REGEXP) if defined?(REGEXP) + const_set("REGEXP", URI::RFC2396_REGEXP) + Parser.new.pattern.each_pair do |sym, str| + unless REGEXP::PATTERN.const_defined?(sym) + REGEXP::PATTERN.const_set(sym, str) + end + end + end + Parser.new.regexp.each_pair do |sym, str| + remove_const(sym) if const_defined?(sym) + const_set(sym, str) end end - DEFAULT_PARSER.regexp.each_pair do |sym, str| - const_set(sym, str) - end - Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor) + self.parser = RFC3986_PARSER module Util # :nodoc: def make_components_hash(klass, array_hash) -- cgit v1.2.3