diff --git a/packages/xml-builder/src/XmlText.spec.ts b/packages/xml-builder/src/XmlText.spec.ts index 2cc642d8ecd8..ecae4fce634c 100644 --- a/packages/xml-builder/src/XmlText.spec.ts +++ b/packages/xml-builder/src/XmlText.spec.ts @@ -3,6 +3,6 @@ import { XmlText } from "./XmlText"; describe("XmlText", () => { it("escapes element text", () => { const text = new XmlText('this & that are < or > "most"'); - expect(text.toString()).toBe('this & that are < or > "most"'); + expect(text.toString()).toBe("this & that are < or > "most""); }); }); diff --git a/packages/xml-builder/src/escape-element.spec.ts b/packages/xml-builder/src/escape-element.spec.ts index 4a1037b618c4..5f660dfb6daf 100644 --- a/packages/xml-builder/src/escape-element.spec.ts +++ b/packages/xml-builder/src/escape-element.spec.ts @@ -1,8 +1,8 @@ import { escapeElement } from "./escape-element"; describe("escape-element", () => { - it("escapes: & < >", () => { - const value = 'abc 123 &<>"%'; - expect(escapeElement(value)).toBe('abc 123 &<>"%'); + it("escapes: & < > \" ' \\n \\r \\u0085 \\u2028", () => { + const value = "abc 123 &<>\"'%\n\r\u0085\u2028"; + expect(escapeElement(value)).toBe("abc 123 &<>"'% …
"); }); }); diff --git a/packages/xml-builder/src/escape-element.ts b/packages/xml-builder/src/escape-element.ts index 564564de664e..68355b74303a 100644 --- a/packages/xml-builder/src/escape-element.ts +++ b/packages/xml-builder/src/escape-element.ts @@ -2,5 +2,14 @@ * Escapes characters that can not be in an XML element. */ export function escapeElement(value: string): string { - return value.replace(/&/g, "&").replace(//g, ">"); + return value + .replace(/&/g, "&") + .replace(/"/g, """) + .replace(/'/g, "'") + .replace(//g, ">") + .replace(/\r/g, " ") + .replace(/\n/g, " ") + .replace(/\u0085/g, "…") + .replace(/\u2028/, "
"); }