Skip to content

Commit

Permalink
quash Ruby 3.4 URI::Parser warnings
Browse files Browse the repository at this point in the history
by using URI::RFC23996_PARSER directly if it exists.
  • Loading branch information
flavorjones committed Jan 2, 2025
1 parent e9bc524 commit 03ec844
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/mechanize/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,27 @@ def self.detect_charset(src)
end

def self.uri_escape str, unsafe = nil
@parser ||= begin
URI::Parser.new
rescue NameError
URI
end

if URI == @parser then
if URI == parser then
unsafe ||= URI::UNSAFE
else
unsafe ||= @parser.regexp[:UNSAFE]
unsafe ||= parser.regexp[:UNSAFE]
end

@parser.escape str, unsafe
parser.escape str, unsafe
end

def self.uri_unescape str
@parser ||= begin
URI::Parser.new
rescue NameError
URI
end

@parser.unescape str
parser.unescape str
end

def self.parser
@parser ||=
if defined?(URI::RFC2396_PARSER)
URI::RFC2396_PARSER
elsif defined?(URI::Parser)
URI::Parser.new
else
URI
end
end
end

0 comments on commit 03ec844

Please sign in to comment.