Skip to content

Commit 95f99a8

Browse files
committed
Replace CGI with URI for Ruby 3.5 support
In Ruby 3.5, most of the cgi gem is removed which includes `CGI.parse`. We can replace this with `URI.decode_www_form` but it has some slight differences. Seems any blank value now always comes back as nil rather nil or an empty string depending so this can be a breaking change. rouge-ruby/rouge#2131
1 parent 2627404 commit 95f99a8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/envied/coercer/envied_string.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def to_float(str)
2727
end
2828

2929
def to_hash(str)
30-
require 'cgi'
31-
::CGI.parse(str).map { |key, values| [key, values[0]] }.to_h
30+
require 'uri'
31+
::URI.decode_www_form(str).map { |key, values| [key, values[0]] }.to_h
3232
end
3333

3434
def to_string(str)

spec/coercer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def coerce(str, type)
255255
{
256256
'a=1' => {'a' => '1'},
257257
'a=1&b=2' => {'a' => '1', 'b' => '2'},
258-
'a=&b=2' => {'a' => '', 'b' => '2'},
258+
'a=&b=2' => {'a' => nil, 'b' => '2'},
259259
'a&b=2' => {'a' => nil, 'b' => '2'},
260260
}.each do |value, hash|
261261
expect(coerce(value, :hash)).to eq hash

spec/envied_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def envied_require(*args, **options)
282282
end
283283

284284
it 'yields hash from string' do
285-
expect(ENVied.FOO).to eq({ 'a' => '1', 'b' => '', 'c' => nil })
285+
expect(ENVied.FOO).to eq({ 'a' => '1', 'b' => nil, 'c' => nil })
286286
end
287287

288288
it 'yields hash from an empty string' do

0 commit comments

Comments
 (0)