Skip to content

Commit

Permalink
chore: Upgrade to go-yaml 1.15.5
Browse files Browse the repository at this point in the history
Requires patch from goccy/go-yaml#565.

Fixes cerbos#2401

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe committed Dec 2, 2024
1 parent aa9a573 commit 4fae0b7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/go-logr/zapr v1.3.0
github.com/go-sql-driver/mysql v1.8.1
github.com/gobwas/glob v0.2.3
github.com/goccy/go-yaml v1.14.3
github.com/goccy/go-yaml v1.15.5
github.com/golang-migrate/migrate/v4 v4.18.1
github.com/google/cel-go v0.21.0
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.14.3 h1:8tVD+aqqPLWisSEhM+6wWoiURWXCx6BwaTKS6ZeITgM=
github.com/goccy/go-yaml v1.14.3/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/goccy/go-yaml v1.15.5 h1:3XvnIQra8CW/7TPV2zks7zR9zUCrPTtW17HSptwXWis=
github.com/goccy/go-yaml v1.15.5/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down
7 changes: 6 additions & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ func Unmarshal[T proto.Message](r io.Reader, factory func() T, opts ...Unmarshal
}

func UnmarshalBytes[T proto.Message](contents []byte, factory func() T, opts ...UnmarshalOpt) (_ []T, _ []SourceCtx, outErr error) {
contentLen := len(bytes.TrimSpace(contents))
if contentLen == 0 {
return nil, nil, nil
}

f, err := parse(contents, true)
if err != nil {
return nil, nil, err
}

if len(f.Docs) == 0 {
if len(bytes.TrimSpace(contents)) > 0 {
if contentLen > 0 {
// Special case for unterminated strings. See test case 20.
return nil, nil, NewUnmarshalError(&sourcev1.Error{
Kind: sourcev1.Error_KIND_PARSE_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion internal/test/testdata/compile/rule_with_no_roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ wantErrors:
position:
line: 14
column: 14
path: "$.resourcePolicy.rules[2].actions"
path: "$.resourcePolicy.rules[2]"
mainDef: "resource_policies/leave_request_20210210.yaml"
10 changes: 5 additions & 5 deletions internal/test/testdata/parser/case_004.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"description": "Invalid type for policyVersion field",
"description": "Invalid type for resource field",
"wantErrors": [
{
"kind": "KIND_PARSE_ERROR",
"position": {
"line": 7,
"column": 9,
"path": "$.resourcePolicy.resource.kind"
"path": "$.resourcePolicy.resource"
},
"message": "expected string value got MappingValue"
"message": "expected string value got Mapping"
}
],
"want": [
Expand All @@ -22,9 +22,9 @@
"position": {
"line": 7,
"column": 9,
"path": "$.resourcePolicy.resource.kind"
"path": "$.resourcePolicy.resource"
},
"message": "expected string value got MappingValue"
"message": "expected string value got Mapping"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions internal/test/testdata/parser/case_023.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{
"kind": "KIND_PARSE_ERROR",
"position": {
"line": 10,
"line": 9,
"column": 7
},
"message": "required ':' and map value"
"message": "non-map value is specified"
}
]
}
6 changes: 3 additions & 3 deletions internal/test/testdata/parser/case_024.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
{
"kind": "KIND_PARSE_ERROR",
"position": {
"line": 13,
"column": 7
"line": 12,
"column": 11
},
"message": "required ':' and map value"
"message": "non-map value is specified"
}
]
}

0 comments on commit 4fae0b7

Please sign in to comment.