fix(apiquery): preserve narrow numeric parameters - #76
fix(apiquery): preserve narrow numeric parameters#76sylvesterkaczmarek wants to merge 2 commits into
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Summary
Preserve narrow Go numeric values when encoding URL query parameters.
Fixes #75.
Problem
internal/apiquerycurrently has two width-related serialization gaps:int8anduint8are not included in the primitive integer cases, so they silently produce no query pair;float32shares thefloat64formatting path and is passed tostrconv.FormatFloatwithbitSize=64, exposing precision introduced only when reflection widens the value to a Gofloat64.A caller can therefore omit a legitimate numeric query parameter entirely, or send a decimal representation different from the source
float32value.Reproduction
On upstream
mainatd082a010f7c6cacf407d8a1581446a7857f9f1bb:Root cause
The primitive switch omitted the 8-bit integer kinds and grouped both floating-point kinds behind:
reflect.Value.Float()returns afloat64, butFormatFloat'sbitSizeargument is specifically what tells it whether the original value should be represented with 32-bit or 64-bit precision.The sibling multipart/form encoder already follows that distinction for primitive values.
Fix
reflect.Int8with the signed integer kinds;reflect.Uint8with the unsigned integer kinds;reflect.Float32withbitSize=32;bitSize=64forreflect.Float64.No query key formatting, array formatting, nesting rules, null handling, or existing wider numeric behavior changes.
Regression coverage
Extended the existing table-driven
TestEncodecases with:int8(-8)->query=-8;uint8(8)->query=8;float32(0.1)->query=0.1.These cases fail on current
mainfor the reasons described above and exercise the realMarshalWithSettingspath rather than an isolated helper.Validation
The branch is based directly on current upstream
mainand is not behind it. The diff is limited to:internal/apiquery/encoder.go;internal/apiquery/query_test.go.Full repository validation is left to the repository's GitHub Actions checks.
Risk
Low. The change only fills missing primitive cases and uses the source floating-point width when choosing the standard-library formatting precision. Existing
int, wider integer, andfloat64output is unchanged.