Skip to content

Commit fd5b81a

Browse files
edmoffoclaude
andauthored
#450: map equals-less tokens to 'true' instead of nil (#455)
parse_pairs in lib/judges/options.rb returned [key, nil] for any token without an equals sign, then normalize_to_h dropped that nil value with .compact before transform_values could turn it into 'true'. Producing 'true' directly inside parse_pairs makes the documented contract hold for both the string and array forms without changing the hash-input behavior that test_with_nil_values pins. Co-authored-by: Claude <noreply@anthropic.com>
1 parent fdd7cca commit fd5b81a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/judges/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def parse_pairs
138138
.map(&:strip)
139139
.reject(&:empty?)
140140
.map { |s| s.split('=', 2) }
141-
.map { |a| a.size == 1 ? [a[0], nil] : a }
141+
.map { |a| a.size == 1 ? [a[0], 'true'] : a }
142142
.reject { |a| a[0].empty? }
143143
.to_h
144144
end

test/test_options.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ def test_with_string
5252
assert_equal(42, opts.b)
5353
end
5454

55+
def test_equals_less_token_in_string
56+
opts = Judges::Options.new('token=abc123,max_speed=100,debug')
57+
assert_equal('abc123', opts.token)
58+
assert_equal(100, opts.max_speed)
59+
assert_equal('true', opts.debug)
60+
end
61+
62+
def test_equals_less_token_in_array
63+
opts = Judges::Options.new(['token=abc123', 'debug'])
64+
assert_equal('abc123', opts.token)
65+
assert_equal('true', opts.debug)
66+
end
67+
5568
def test_with_hash
5669
opts = Judges::Options.new('foo' => 42, 'bar' => 'hello')
5770
assert_equal(42, opts.foo)

0 commit comments

Comments
 (0)