Drop empty-key pairs in query_string_parser#10
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6
Summary
Addressable::URI.form_unencodereturns pairs withnilor empty-string keys for stray delimiters in the input (&foo=bar,=value,&&, etc.). These polluted the emitted record with an"" => ""entrynilor empty before building the output hashfoo=) are preserved — they represent an intentional empty parameterBehavior
&partnerid=12345{ "" => "", "partnerid" => "12345" }{ "partnerid" => "12345" }=value&foo=bar{ "" => "value", "foo" => "bar" }{ "foo" => "bar" }&&foo=bar&&"" => ""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)test_filter_drops_empty_keyscovering leading/middle/trailing delimiters and the intentionally empty-value case🤖 Generated with Claude Code