Skip to content

model: decode JSON escapes in quoted float values - #1048

Open
AmanBoronbaev wants to merge 1 commit into
prometheus:mainfrom
AmanBoronbaev:fix/model-json-escaped-floats
Open

AmanBoronbaev wants to merge 1 commit into
prometheus:mainfrom
AmanBoronbaev:fix/model-json-escaped-floats

Conversation

@AmanBoronbaev

Copy link
Copy Markdown

SampleValue and FloatString strip the surrounding JSON quotes but pass escape sequences directly to strconv.ParseFloat. As a result, the valid JSON string "\u0031" fails to decode, while the equivalent "1" succeeds.

Unescape strings containing backslashes with encoding/json before parsing the float. Share this logic between sample and histogram values, preserving the existing direct parsing path for unescaped strings and the rejection of unquoted values.

Add regression coverage for zero, negative zero, the largest float64, the smallest subnormal, NaN, both infinities, overflow and invalid input. The same cases run through encoding/json and, on Go 1.27, encoding/json/v2. Add a benchmark for plain and escaped sample values; the plain path remains at 0 B/op and 0 allocs/op in local measurements.

Validation:

  • Full repository go test ./... passes on Go 1.27.4. Proxy environment variables were cleared for the test process so the HTTP proxy tests could control their own environment.
  • go test -race ./model passes; model tests also pass on Go 1.26.11.
  • go vet ./..., the repository's golangci-lint v2.14.0 configuration, formatting and license checks pass.
  • Before the fix, 16 of the 24 new JSON v1 cases fail; after the fix all 48 cases across JSON v1/v2 pass.

@gotjosh, requesting review as directed by CONTRIBUTING.md.

Signed-off-by: Aman <149809343+AmanBoronbaev@users.noreply.github.com>
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.

1 participant