Commit b41538d
committed
fix: improve std.manifestXmlJsonml empty tags, array/object attrs, and HTML escaping
Motivation:
std.manifestXmlJsonml had several issues:
1. Empty tag names were rejected with an error, while go-jsonnet and jrsonnet
accept them and produce <></> syntax
2. Array/object attribute values were rejected with an error, while go-jsonnet
serializes them as JSON strings
3. The empty tag path did not escape HTML entities in attribute values,
producing inconsistent and potentially invalid XML compared to the non-empty
tag path which uses scalatags (which escapes automatically)
Modification:
- Added escapeHtmlAttr helper that escapes ", <, >, & and drops invalid XML 1.0
control characters (below 0x20 except \n, \r, \t) to match scalatags behavior
- Added attrValue helper that converts ujson.Value to its string representation
for XML attributes, eliminating code duplication between empty and non-empty
tag paths. Str passes through as-is; Num uses ujson.write for consistent
formatting; True/False/Null use literals; arrays/objects serialize to JSON
- Added emptyTag helper to render empty tag names with proper attribute escaping
- Changed array/object attribute handling from error to JSON serialization via
ujson.write (matching go-jsonnet behavior)
Result:
- Empty tag names now produce <></> syntax (aligns with go-jsonnet, jrsonnet)
- Array/object attribute values now serialize as JSON strings instead of
throwing errors (aligns with go-jsonnet)
- HTML entities are now consistently escaped in both empty and non-empty tag
paths, producing valid XML 1.0 output (aligns with jrsonnet)
- Code is cleaner with shared attrValue helper eliminating duplication
Test coverage:
22 assertions covering empty tags, array/object attributes, HTML escaping,
numeric/boolean/null attributes, single quotes, nested empty tags, and mixed
children. All tests pass.1 parent e686d89 commit b41538d
3 files changed
Lines changed: 100 additions & 22 deletions
File tree
- sjsonnet
- src/sjsonnet/stdlib
- test/resources/new_test_suite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
623 | 666 | | |
624 | 667 | | |
625 | 668 | | |
626 | 669 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
648 | 679 | | |
649 | | - | |
| 680 | + | |
| 681 | + | |
650 | 682 | | |
651 | 683 | | |
652 | 684 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments