Skip to content

Commit e564d56

Browse files
authored
Merge pull request #662 from sparklemotion/flavorjones-ruby-34-warnings
quash Ruby 3.4 URI::Parser warnings
2 parents e9bc524 + be2de52 commit e564d56

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## next / unreleased
44

55
* Quash frozen string warnings in Ruby 3.4. (#661) @simpl1g
6+
* Quash URI::Parser warnings in Ruby 3.4. (#662) @flavorjones
67

78

89
## 2.12.2 / 2023-10-02

lib/mechanize/util.rb

+14-16
Original file line numberDiff line numberDiff line change
@@ -134,29 +134,27 @@ def self.detect_charset(src)
134134
end
135135

136136
def self.uri_escape str, unsafe = nil
137-
@parser ||= begin
138-
URI::Parser.new
139-
rescue NameError
140-
URI
141-
end
142-
143-
if URI == @parser then
137+
if URI == parser then
144138
unsafe ||= URI::UNSAFE
145139
else
146-
unsafe ||= @parser.regexp[:UNSAFE]
140+
unsafe ||= parser.regexp[:UNSAFE]
147141
end
148142

149-
@parser.escape str, unsafe
143+
parser.escape str, unsafe
150144
end
151145

152146
def self.uri_unescape str
153-
@parser ||= begin
154-
URI::Parser.new
155-
rescue NameError
156-
URI
157-
end
158-
159-
@parser.unescape str
147+
parser.unescape str
160148
end
161149

150+
def self.parser
151+
@parser ||=
152+
if defined?(URI::RFC2396_PARSER)
153+
URI::RFC2396_PARSER
154+
elsif defined?(URI::Parser)
155+
URI::Parser.new
156+
else
157+
URI
158+
end
159+
end
162160
end

0 commit comments

Comments
 (0)