mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
build/generate-extended-cases: Fix testcase loader to use json.Number. (#8429)
The testcase generator had a bug where very large numbers would be parsed incorrectly, truncating the lower bits off their values. This was discovered to be caused by the YAML library defaulting to parsing all numeric values into floating point numbers, which lose precision at larger sizes. The fix was to provide the YAML unmarshaling function with the appropriate equivalent of `(*json.Decoder).UseNumber()` at the callsite. This causes the YAML library to use `json.Number` types by default, just as we expect almost everywhere else in Rego. Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
This commit is contained in:
@@ -2,6 +2,7 @@ package cases
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
@@ -135,7 +136,11 @@ func LoadIrExtendedTestCasesFiltered(filters ...Filters) ([]ExtendedSet, error)
|
||||
}
|
||||
|
||||
var x ExtendedSet
|
||||
if err := yaml.Unmarshal(f, &x); err != nil {
|
||||
useNumber := yaml.JSONOpt(func(d *json.Decoder) *json.Decoder {
|
||||
d.UseNumber()
|
||||
return d
|
||||
})
|
||||
if err := yaml.Unmarshal(f, &x, useNumber); err != nil {
|
||||
return fmt.Errorf("%s: %w", path, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user