Fix `Puma::StateFile#load` returns empty string instead of nil (#2810)
Bug introduced in 2b6968f9d4
#2784
Until 5.5.2, empty values were read as `nil`.
Since 5.6.0, empty values are read as `""`.
This commit is contained in:
parent
e0753de846
commit
93815b234b
|
@ -50,6 +50,7 @@ module Puma
|
|||
v = v.strip
|
||||
@options[k] =
|
||||
case v
|
||||
when '' then nil
|
||||
when /\A\d+\z/ then v.to_i
|
||||
when /\A\d+\.\d+\z/ then v.to_f
|
||||
else v.gsub(/\A"|"\z/, '')
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require_relative "helper"
|
||||
require_relative "helpers/tmp_path"
|
||||
|
||||
require 'puma/state_file'
|
||||
|
||||
class TestStateFile < Minitest::Test
|
||||
include TmpPath
|
||||
|
||||
def test_load_empty_value_as_nil
|
||||
state_path = tmp_path('.state')
|
||||
File.write state_path, <<-STATE
|
||||
---
|
||||
pid: 123456
|
||||
control_url:
|
||||
control_auth_token:
|
||||
running_from: "/path/to/app"
|
||||
STATE
|
||||
|
||||
sf = Puma::StateFile.new
|
||||
sf.load(state_path)
|
||||
assert_equal 123456, sf.pid
|
||||
assert_equal '/path/to/app', sf.running_from
|
||||
assert_nil sf.control_url
|
||||
assert_nil sf.control_auth_token
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue