diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-07-17 18:53:54 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-07-19 00:50:35 +0000 |
commit | 08e449d89baf1aeee87f084e1cd55bfe3b9cc46a (patch) | |
tree | bf9151672b6135211938661de846a22c7d6eaff9 /lib | |
parent | 8df74deab1a4b39458835f7ea0d57137b91a3466 (diff) | |
download | ruby-08e449d89baf1aeee87f084e1cd55bfe3b9cc46a.tar.gz |
[ruby/uri] Added URI.parser= method for switch back to RFC2396_Parser
https://github.com/ruby/uri/commit/d7dc19ad3f
Diffstat (limited to 'lib')
-rw-r--r-- | lib/uri/common.rb | 34 |
1 files changed, 22 insertions, 12 deletions
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) |