Skip to content

Fix handling of string keys that are valid ints in URIs - #219

Open
czechboy0 wants to merge 3 commits into
apple:mainfrom
czechboy0:hd-uri-coder-int-keys
Open

czechboy0 wants to merge 3 commits into
apple:mainfrom
czechboy0:hd-uri-coder-int-keys

Conversation

@czechboy0

Copy link
Copy Markdown
Contributor

Motivation

A fun one. String coding keys that are valid integers were taking an unexpected codepath and lead to a crash due
to a broken invariant.

When parsing URIs (such as query items), the first value that's being decoded helps decide whether we'll treat
the collection as an array or a dictionary. If the coding key is a valid int, it's an array, otherwise a dictionary.

The problem is that string keys that are valid ints were getting converted successfully to ints, meaning that dictionaries
with int-like string keys were taking the wrong path.

Modifications

Don't auto-convert coding keys, instead pass explicit string/int keys in the keyed/unkeyed coder implementations.

Result

No more crash for a specially crafted query string.

Test Plan

Added unit tests for this, both on the encoding and the decoding side.

@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant