Commit 4217868
x/exp/schema: fix reserved keyword handling and add validation
Add a tokenReservedKeyword token type to the schema parser's lexer, matching the approach used in the main Cedar parser. Previously, reserved keywords like "true", "false", "in", "if", etc. were lexed as plain identifiers, which meant the parser silently accepted them in positions where they should be rejected (e.g. `entity true;`, `type if = String;`).
Bugs fixed:
- Reserved Cedar keywords were accepted as entity, type, and action names, namespace path components, and attribute names without quoting. The parser now rejects these with a clear error message.
- __cedar as a definition name (entity, type, enum) was silently accepted. These are now rejected while still allowing __cedar as an action name, attribute name, and type reference prefix, which matches the Cedar Rust behavior.
- Duplicate annotations (e.g. `@doc("a") @doc("b")`) were silently accepted with last-wins semantics. The parser now rejects duplicates.
- Duplicate principal, resource, or context declarations within appliesTo were silently accepted. The parser now rejects duplicates.
- Empty principal or resource type lists in appliesTo (e.g. `principal: []`) were silently accepted, producing a meaningless empty list. The parser now rejects these.
- appliesTo blocks missing a principal or resource declaration were accepted. The parser now requires both.
- MarshalSchema emitted reserved keywords as bare identifiers in attribute and action names (e.g. `true: String`), producing output that could not be re-parsed. isValidIdent now checks for reserved keywords and the marshaler quotes them.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-Off-By: Patrick Jakubowski <patrick.jakubowski@strongdm.com>1 parent 682b8a0 commit 4217868
File tree
6 files changed
+195
-19
lines changed- internal/parser
- x/exp/schema/internal/parser
6 files changed
+195
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
488 | 491 | | |
489 | 492 | | |
490 | 493 | | |
491 | | - | |
| 494 | + | |
492 | 495 | | |
493 | 496 | | |
494 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
314 | | - | |
| 315 | + | |
315 | 316 | | |
316 | 317 | | |
317 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
148 | 156 | | |
149 | 157 | | |
150 | 158 | | |
| |||
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
216 | | - | |
| 224 | + | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
| |||
333 | 341 | | |
334 | 342 | | |
335 | 343 | | |
336 | | - | |
| 344 | + | |
337 | 345 | | |
338 | 346 | | |
339 | 347 | | |
| |||
431 | 439 | | |
432 | 440 | | |
433 | 441 | | |
434 | | - | |
| 442 | + | |
435 | 443 | | |
436 | 444 | | |
437 | 445 | | |
| |||
459 | 467 | | |
460 | 468 | | |
461 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
462 | 473 | | |
463 | 474 | | |
464 | 475 | | |
| |||
469 | 480 | | |
470 | 481 | | |
471 | 482 | | |
| 483 | + | |
| 484 | + | |
472 | 485 | | |
473 | | - | |
| 486 | + | |
474 | 487 | | |
475 | 488 | | |
476 | 489 | | |
| |||
494 | 507 | | |
495 | 508 | | |
496 | 509 | | |
| 510 | + | |
| 511 | + | |
497 | 512 | | |
498 | | - | |
| 513 | + | |
499 | 514 | | |
500 | 515 | | |
501 | 516 | | |
| |||
570 | 585 | | |
571 | 586 | | |
572 | 587 | | |
573 | | - | |
574 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
575 | 593 | | |
576 | 594 | | |
577 | 595 | | |
578 | 596 | | |
579 | 597 | | |
580 | | - | |
| 598 | + | |
581 | 599 | | |
582 | 600 | | |
583 | 601 | | |
| |||
674 | 692 | | |
675 | 693 | | |
676 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
677 | 698 | | |
678 | 699 | | |
679 | 700 | | |
| |||
683 | 704 | | |
684 | 705 | | |
685 | 706 | | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
686 | 711 | | |
687 | 712 | | |
688 | 713 | | |
| |||
693 | 718 | | |
694 | 719 | | |
695 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
696 | 724 | | |
697 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
698 | 730 | | |
699 | 731 | | |
700 | 732 | | |
| |||
705 | 737 | | |
706 | 738 | | |
707 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
708 | 743 | | |
709 | 744 | | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
710 | 749 | | |
711 | 750 | | |
712 | 751 | | |
| |||
727 | 766 | | |
728 | 767 | | |
729 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
730 | 775 | | |
731 | 776 | | |
732 | 777 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
| 163 | + | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
| |||
0 commit comments