Skip to content

Commit

Permalink
fix: codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 2, 2022
1 parent 1881630 commit 46faefd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/swc_xml_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn normalize_attribute_value(value: &str) -> String {
let mut normalized = String::with_capacity(value.len() + 2);

normalized.push('"');
normalized.push_str(value);
normalized.push_str(&escape_string(value, true));
normalized.push('"');

normalized
Expand Down Expand Up @@ -463,7 +463,7 @@ fn escape_string(value: &str, is_attribute_mode: bool) -> String {
result.push_str("&");
}
'"' if is_attribute_mode => result.push_str("""),
'<' if !is_attribute_mode => {
'<' if is_attribute_mode => {
result.push_str("&lt;");
}
'>' if !is_attribute_mode => {
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_xml_codegen/tests/fixture/base/input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<foo attributeName="He said &quot;OK&quot;"></foo>
<foo attributeName="He said &lt;OK&lt;"></foo>
<foo attributeName="He said &gt;OK&gt;"></foo>
<foo attributeName="He said >OK>"></foo>
<foo attributeName="He said &apos;OK&apos;"></foo>
<foo attributeName="He said &amp;OK&amp;"></foo>
</note>
6 changes: 6 additions & 0 deletions crates/swc_xml_codegen/tests/fixture/base/output.min.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<foo attributeName="He said &quot;OK&quot;"/>
<foo attributeName="He said &lt;OK&lt;"/>
<foo attributeName="He said >OK>"/>
<foo attributeName="He said >OK>"/>
<foo attributeName="He said 'OK'"/>
<foo attributeName="He said &amp;OK&amp;"/>
</note>
6 changes: 6 additions & 0 deletions crates/swc_xml_codegen/tests/fixture/base/output.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<foo attributeName="He said &quot;OK&quot;" />
<foo attributeName="He said &lt;OK&lt;" />
<foo attributeName="He said >OK>" />
<foo attributeName="He said >OK>" />
<foo attributeName="He said 'OK'" />
<foo attributeName="He said &amp;OK&amp;" />
</note>

0 comments on commit 46faefd

Please sign in to comment.