Commit 4b02ba9
committed
fix: keep manifestXmlJsonml output well-formed XML
Motivation:
Jsonnet documents std.manifestXmlJsonml as converting a JsonML-encoded value to a
string containing XML. XML 1.0 start-tags, end-tags, empty-element tags, and
attributes all require a non-empty XML Name. The previous draft followed other
implementations by accepting empty tag names, but that emits strings such as <></>,
which are not XML. The existing scalatags-backed implementation also rejected some
valid XML names through scalatags' narrower tag-name checks and could not stringify
array/object attribute values while keeping XML escaping correct.
Modification:
Replace the scalatags-dependent rendering path with a small XML renderer for JsonML.
Validate element and attribute names with the XML 1.0 Name production, stringify
array/object attribute values with compact JSON, and escape XML-sensitive characters in
text and attribute values. Add regressions for rejected empty/invalid names, valid XML
names such as namespace-style and dotted names, and array/object attribute values.
Result:
sjsonnet now rejects JsonML names that cannot produce XML instead of emitting invalid
markup. It also accepts XML-valid names that scalatags rejected, and renders complex
attribute values as escaped XML attribute strings. Other implementations still accept
some invalid XML cases, so this change intentionally follows the Jsonnet documentation's
XML contract instead of matching those invalid outputs.
References:
- https://jsonnet.org/ref/stdlib.html#std-manifestXmlJsonml
- https://www.w3.org/TR/xml/#NT-Name
- https://www.w3.org/TR/xml/#sec-starttags1 parent e686d89 commit 4b02ba9
9 files changed
Lines changed: 116 additions & 26 deletions
File tree
- sjsonnet
- src/sjsonnet/stdlib
- test/resources/new_test_suite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
40 | 125 | | |
41 | 126 | | |
42 | 127 | | |
| |||
619 | 704 | | |
620 | 705 | | |
621 | 706 | | |
622 | | - | |
623 | | - | |
| 707 | + | |
624 | 708 | | |
625 | | - | |
| 709 | + | |
626 | 710 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
648 | 722 | | |
649 | | - | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
650 | 727 | | |
651 | 728 | | |
652 | 729 | | |
653 | 730 | | |
654 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
655 | 734 | | |
656 | 735 | | |
657 | 736 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments