Skip to content

Drop empty-key pairs in query_string_parser#10

Merged
daichirata merged 1 commit into
masterfrom
reject-empty-keys
May 22, 2026
Merged

Drop empty-key pairs in query_string_parser#10
daichirata merged 1 commit into
masterfrom
reject-empty-keys

Conversation

@daichirata

Copy link
Copy Markdown
Owner

Closes #6

Summary

  • Addressable::URI.form_unencode returns pairs with nil or empty-string keys for stray delimiters in the input (&foo=bar, =value, &&, etc.). These polluted the emitted record with an "" => "" entry
  • Filter pairs where the key is nil or empty before building the output hash
  • Pairs with an empty value but a real key (foo=) are preserved — they represent an intentional empty parameter

Behavior

Input Before After
&partnerid=12345 { "" => "", "partnerid" => "12345" } { "partnerid" => "12345" }
=value&foo=bar { "" => "value", "foo" => "bar" } { "foo" => "bar" }
&&foo=bar&& extra "" => "" pairs { "foo" => "bar" }
foo=&bar=baz (unchanged) { "foo" => "", "bar" => "baz" } { "foo" => "", "bar" => "baz" }

Test plan

  • bundle exec rake test (21 tests / 92 assertions / 0 failures)
  • Added test_filter_drops_empty_keys covering leading/middle/trailing delimiters and the intentionally empty-value case
  • GitHub Actions matrix passes on Ruby 3.2 / 3.3 / 3.4 / 4.0

🤖 Generated with Claude Code

URLs in the wild often contain stray delimiters that produce
`Addressable::URI.form_unencode` pairs with a nil or empty key, e.g.
`/path?&foo=bar` -> `[[nil, nil], ["foo", "bar"]]`. These empty
pairs polluted the emitted record with an `"" => ""` entry.

Reject pairs whose key is nil or empty before building the output
hash. Pairs with an empty value but real key (`foo=`) are preserved,
since they represent an intentional empty-string parameter.

Closes #6

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@daichirata daichirata merged commit f01d7cc into master May 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with "empty" params

1 participant