From a20b85b5e88bd5a8ecd483165727073272385cb9 Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Sun, 15 Mar 2026 14:58:45 +0900 Subject: [PATCH] Avoid to call obsolete methods Currently, when a user call `URI.regexp`, two messages are shown. ``` $ ruby -w -e "require 'uri'; URI.regexp('https')" -e:1: warning: URI.regexp is obsolete uri-1.1.1/lib/uri/common.rb:340: warning: URI::RFC3986_PARSER.make_regexp is obsolete. Use URI::RFC2396_PARSER.make_regexp explicitly. ``` I think this is a bit redundant. I updated to call `URI::RFC2396_PARSER.make_regexp` directly since only RFC2396 parser supports `.make_regexp`. I also updated the message to indicate that `URI::RFC2396.make_regexp` must be used if you still want to use `URI.regexp`. This issue also exists in `URI.extract`, so I applied the same fix there. --- lib/uri/common.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 1800836..ce54000 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -299,8 +299,8 @@ def self.join(*str) # # => ["http://foo.example.com/bla", "mailto:test@example.com"] # def self.extract(str, schemes = nil, &block) # :nodoc: - warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE - PARSER.extract(str, schemes, &block) + warn "URI.extract is obsolete. Please use URI::RFC2396_PARSER.extract instead.", uplevel: 1 if $VERBOSE + URI::RFC2396_PARSER.extract(str, schemes, &block) end # @@ -336,8 +336,8 @@ def self.extract(str, schemes = nil, &block) # :nodoc: # end # def self.regexp(schemes = nil)# :nodoc: - warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE - PARSER.make_regexp(schemes) + warn "URI.regexp is obsolete. Please use URI::RFC2396_PARSER.make_regexp instead.", uplevel: 1 if $VERBOSE + RFC2396_PARSER.make_regexp(schemes) end TBLENCWWWCOMP_ = {} # :nodoc: