Description
When running the test suite under Go 1.27+, TestNormalizeJSON_ReturnsMarshalError in schema_validation/validate_document_test.go fails and panics with a SIGSEGV nil pointer dereference.
Root Cause
In Go 1.27+, encoding/json.Marshal supports marshaling maps with integer keys (such as map[interface{}]interface{}{1: "one"}) by converting the integer keys to strings ({"1":"one"}), rather than returning an unsupported type: map[interface {}]interface {} error as earlier Go versions did.
Because normalizeJSON(payload) now succeeds without error:
assert.Error(t, err) fails.
- Line 195 unconditionally evaluates
err.Error(), which dereferences a nil pointer and panics.
Stack Trace
=== RUN TestNormalizeJSON_ReturnsMarshalError
validate_document_test.go:193: Expected nil, but got: map[string]interface {}{"invalid":map[string]interface {}{"1":"one"}, "openapi":"3.1.0"}
validate_document_test.go:194: An error is expected but got nil.
--- FAIL: TestNormalizeJSON_ReturnsMarshalError (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x93fc5d]
goroutine 21 [running]:
...
github.com/pb33f/libopenapi-validator/schema_validation.TestNormalizeJSON_ReturnsMarshalError(...)
schema_validation/validate_document_test.go:195 +0x19d
Affected Tests
The following tests in schema_validation/validate_document_test.go construct map[interface{}]interface{}{1: "one"} expecting json.Marshal / normalizeJSON to produce an error:
TestNormalizeJSON_ReturnsMarshalError (line 184)
TestValidateDocument_NormalizationErrorDoesNotValidateNil (line 198)
TestValidateDocument_CorruptSpecJSONBytesFallbackNormalizationError (line 228)
Description
When running the test suite under Go 1.27+,
TestNormalizeJSON_ReturnsMarshalErrorinschema_validation/validate_document_test.gofails and panics with aSIGSEGVnil pointer dereference.Root Cause
In Go 1.27+,
encoding/json.Marshalsupports marshaling maps with integer keys (such asmap[interface{}]interface{}{1: "one"}) by converting the integer keys to strings ({"1":"one"}), rather than returning anunsupported type: map[interface {}]interface {}error as earlier Go versions did.Because
normalizeJSON(payload)now succeeds without error:assert.Error(t, err)fails.err.Error(), which dereferences a nil pointer and panics.Stack Trace
Affected Tests
The following tests in
schema_validation/validate_document_test.goconstructmap[interface{}]interface{}{1: "one"}expectingjson.Marshal/normalizeJSONto produce an error:TestNormalizeJSON_ReturnsMarshalError(line 184)TestValidateDocument_NormalizationErrorDoesNotValidateNil(line 198)TestValidateDocument_CorruptSpecJSONBytesFallbackNormalizationError(line 228)