fix(apiform): preserve float32 precision in comma arrays - #78
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
fix(apiform): preserve float32 precision in comma arrays#78sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
Conversation
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.
Summary
Keep multipart comma-array
float32serialization consistent with the existing scalarfloat32path.Fixes #77.
Problem
internal/apiformalready formats scalarfloat32values with 32-bit precision, butFormatCommaarrays combinefloat32andfloat64behind a 64-bit formatting call.That means the same source value can be represented differently depending only on whether it appears by itself or inside a comma-delimited form field.
For example, current
mainserializes:as:
but:
with
FormatCommaas:Root cause
The primitive form path correctly distinguishes widths:
The comma-array path instead uses one branch for both kinds and always passes
bitSize=64. Reflection returns floating-point values asfloat64, so the 64-bit formatting request preserves digits introduced by widening the originalfloat32.Fix
Split the comma-array branch by source kind:
reflect.Float32->FormatFloat(..., 32)reflect.Float64->FormatFloat(..., 64)No multipart boundaries, field names, array-format selection, integer formatting, boolean formatting, or
float64output changes.Regression coverage
The existing table-driven form encoder test now includes:
float32(0.1)control showing the existing expected representation;FormatComma[]float32{0.1, 1.5}regression requiring0.1,1.5.The comma-array case fails on current upstream
main, while the scalar control demonstrates the consistency requirement directly.Validation
The branch is based directly on upstream
mainatd082a010f7c6cacf407d8a1581446a7857f9f1bband is not behind it.Production diff: 3 additions and 1 deletion in
internal/apiform/encoder.go, plus focused table-driven coverage ininternal/apiform/form_test.go.Full repository validation is left to the repository's GitHub Actions checks.
Risk
Low. Only the textual formatting of
float32values insideFormatCommaarrays changes, and it becomes identical to the width-aware behavior already used for scalarfloat32fields.float64and all non-floating form values are unchanged.