File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ func (p *Policy) fromCedar(parser *parser) error {
112112 if err = parser .resource (newPolicy ); err != nil {
113113 return err
114114 }
115+ parser .skipAtMostOnce ("," )
115116 if err = parser .exact (")" ); err != nil {
116117 return err
117118 }
@@ -155,6 +156,13 @@ func (p *parser) exact(tok string) error {
155156 return nil
156157}
157158
159+ func (p * parser ) skipAtMostOnce (tok string ) {
160+ t := p .peek ()
161+ if t .Text == tok {
162+ p .advance ()
163+ }
164+ }
165+
158166func (p * parser ) errorf (s string , args ... interface {}) error {
159167 var t Token
160168 if p .pos < len (p .tokens ) {
Original file line number Diff line number Diff line change @@ -590,7 +590,7 @@ func TestParsePolicySet(t *testing.T) {
590590 policyStr := []byte (`permit (
591591 principal,
592592 action,
593- resource
593+ resource,
594594 );` )
595595
596596 var policies parser.PolicySlice
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ func TestPolicyCedar(t *testing.T) {
7171 t .Parallel ()
7272
7373 // Taken from https://docs.cedarpolicy.com/policies/syntax-policy.html
74- policyStr : = `permit (
74+ const policyStr = `permit (
7575 principal,
7676 action == Action::"editPhoto",
7777 resource
@@ -84,6 +84,29 @@ when { resource.owner == principal };`
8484 testutil .Equals (t , string (policy .MarshalCedar ()), policyStr )
8585}
8686
87+ func TestPolicyCedar_TrailingComma (t * testing.T ) {
88+ t .Parallel ()
89+
90+ const policyStr = `permit (
91+ principal,
92+ action == Action::"editPhoto",
93+ resource
94+ )
95+ when { resource.owner == principal };`
96+
97+ const policyStrTrailingComma = `permit (
98+ principal,
99+ action == Action::"editPhoto",
100+ resource,
101+ )
102+ when { resource.owner == principal };`
103+
104+ var policy cedar.Policy
105+ testutil .OK (t , policy .UnmarshalCedar ([]byte (policyStrTrailingComma )))
106+
107+ testutil .Equals (t , string (policy .MarshalCedar ()), policyStr )
108+ }
109+
87110func TestPolicyAST (t * testing.T ) {
88111 t .Parallel ()
89112
You can’t perform that action at this time.
0 commit comments