Skip to content

Commit

Permalink
Fix escaping for JS string rendering (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
LcTwisk committed Mar 11, 2021
1 parent b38c36a commit 35fa701
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/actions/render.js
Expand Up @@ -153,8 +153,11 @@ const substitutionsForOutputType = type => {
return [
{ search: "{{s}}", replace: "$s" },
{ search: "{{d}}", replace: "$d" },
{ search: "\b", replace: "\\b" },
{ search: "\f", replace: "\\f" },
{ search: "\r", replace: "\\r" },
{ search: "\n", replace: "\\n" },
{ search: "\\", replace: "\\\\" },
{ search: "\t", replace: "\\t" },
{ search: '"', replace: '\\"' }
];
}
Expand Down
12 changes: 6 additions & 6 deletions tests/actions/__snapshots__/render.test.js.snap
Expand Up @@ -21,7 +21,7 @@ Result {
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"We support nesting as deep as you'd like\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help: %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"The following characters need special handling for some output types: @ ? < & ' \\\\\\". And then there is the percent-sign: most cases should be replaced (e.g. 99.9% and %1 and %.1) but not the percentage-sign in strings like %1$s or %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\\\\\nYou better watch out!\\\\\\\\n\\\\\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\nYou better watch out!\\\\n\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Accessible.RegularComponent.COPY\\": \\"This is a component with accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"This is the hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"This is the label\\"
Expand Down Expand Up @@ -125,7 +125,7 @@ It may also contain empty lines to break up text into paragraphs.\\";
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"We support nesting as deep as you'd like\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help: %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"The following characters need special handling for some output types: @ ? < & ' \\\\\\". And then there is the percent-sign: most cases should be replaced (e.g. 99.9% and %1 and %.1) but not the percentage-sign in strings like %1$s or %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\\\\\nYou better watch out!\\\\\\\\n\\\\\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\nYou better watch out!\\\\n\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Accessible.RegularComponent.COPY\\": \\"This is a component with accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"This is the hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"This is the label\\"
Expand Down Expand Up @@ -729,7 +729,7 @@ Result {
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"We support nesting as deep as you'd like\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help: %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"The following characters need special handling for some output types: @ ? < & ' \\\\\\". And then there is the percent-sign: most cases should be replaced (e.g. 99.9% and %1 and %.1) but not the percentage-sign in strings like %1$s or %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\\\\\nYou better watch out!\\\\\\\\n\\\\\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\nYou better watch out!\\\\n\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Accessible.RegularComponent.COPY\\": \\"This is a component with accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"This is the hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"This is the label\\"
Expand Down Expand Up @@ -817,7 +817,7 @@ It may also contain empty lines to break up text into paragraphs.\\";
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"Je kan zo veel lagen maken als je zelf wil\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"De volgende karakters moeten herschreven voor sommige output types: @ ? < & ' \\\\\\". En let op met het procent-teken: in de meeste gevallen moet het vervangen worden (e.g. 99.9% en %1 en %.1) maar niet het procent-teken in strings als %1$s of %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"Dit is een string van meerdere regels die <a href=\\\\\\"about:blank\\\\\\">links</a> kan bevatten.\\\\\\\\nLet maar eens op!\\\\\\\\n\\\\\\\\nDe tekst kan zelfs witregels bevatten!\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"Dit is een string van meerdere regels die <a href=\\\\\\"about:blank\\\\\\">links</a> kan bevatten.\\\\nLet maar eens op!\\\\n\\\\nDe tekst kan zelfs witregels bevatten!\\",
\\"Accessible.RegularComponent.COPY\\": \\"Dit is een component met accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"Dit is de hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"Dit is de label\\"
Expand Down Expand Up @@ -1144,7 +1144,7 @@ Result {
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"We support nesting as deep as you'd like\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help: %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"The following characters need special handling for some output types: @ ? < & ' \\\\\\". And then there is the percent-sign: most cases should be replaced (e.g. 99.9% and %1 and %.1) but not the percentage-sign in strings like %1$s or %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\\\\\nYou better watch out!\\\\\\\\n\\\\\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"This is a multiline string that may contain <a href=\\\\\\"about:blank\\\\\\">links</a>\\\\nYou better watch out!\\\\n\\\\nIt may also contain empty lines to break up text into paragraphs.\\",
\\"Accessible.RegularComponent.COPY\\": \\"This is a component with accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"This is the hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"This is the label\\"
Expand Down Expand Up @@ -1244,7 +1244,7 @@ It may also contain empty lines to break up text into paragraphs.\\";
\\"Something.With.An.Arbitrary.Amount.Of.Nesting.COPY\\": \\"Je kan zo veel lagen maken als je zelf wil\\",
\\"Delivery.Widget.Title.COPY\\": \\"Help %1$s\\",
\\"Delivery.Widget.SpecialCharacters.COPY\\": \\"De volgende karakters moeten herschreven voor sommige output types: @ ? < & ' \\\\\\". En let op met het procent-teken: in de meeste gevallen moet het vervangen worden (e.g. 99.9% en %1 en %.1) maar niet het procent-teken in strings als %1$s of %42$d.\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"Dit is een string van meerdere regels die <a href=\\\\\\"about:blank\\\\\\">links</a> kan bevatten.\\\\\\\\nLet maar eens op!\\\\\\\\n\\\\\\\\nDe tekst kan zelfs witregels bevatten!\\",
\\"Delivery.Widget.MultilineStrings.COPY\\": \\"Dit is een string van meerdere regels die <a href=\\\\\\"about:blank\\\\\\">links</a> kan bevatten.\\\\nLet maar eens op!\\\\n\\\\nDe tekst kan zelfs witregels bevatten!\\",
\\"Accessible.RegularComponent.COPY\\": \\"Dit is een component met accessiblity support\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.HINT\\": \\"Dit is de hint\\",
\\"Accessible.RegularComponent.ACCESSIBILITY.LABEL\\": \\"Dit is de label\\"
Expand Down

0 comments on commit 35fa701

Please sign in to comment.