k6 icon indicating copy to clipboard operation
k6 copied to clipboard

fix: handle NaN and Infinity float values in gRPC

Open ariasmn opened this issue 8 months ago • 3 comments
trafficstars

Fixes (?): https://github.com/grafana/k6/issues/3990

The problem was in this specific line:

https://github.com/grafana/k6/blob/a74d8039a2be85a7f24199f92ae1680426ee44d7/internal/js/modules/k6/grpc/client.go#L363

This MarshalJSON implemented in Sobek uses a copy of JSON.stringify() under the hood, and per JSON RFC, neither Infinity or NaN as values are accepted as valid numbers.

However, since we rely on ProtoJSON, which does support special strings "Infinity" and "NaN", I guess that the idea would be to "normalize" them as a string format before marshaling, which is what this PR implements.

ariasmn avatar Mar 15 '25 11:03 ariasmn