From 664760c99c6e2d3cf5e31d74fb443d2e7e990500 Mon Sep 17 00:00:00 2001 From: "matt@emericklaw.co.uk" Date: Thu, 6 Sep 2018 14:38:26 +0100 Subject: [PATCH] Fixes #227 --- src/formatting/formatters/v2-xml-formatter.ts | 2 +- src/test/extension.test.ts | 3 +++ src/test/test-data/issue-227.formatted.xml | 19 +++++++++++++++++++ src/test/test-data/issue-227.unformatted.xml | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/test-data/issue-227.formatted.xml create mode 100644 src/test/test-data/issue-227.unformatted.xml diff --git a/src/formatting/formatters/v2-xml-formatter.ts b/src/formatting/formatters/v2-xml-formatter.ts index f7934d3..1a91e43 100644 --- a/src/formatting/formatters/v2-xml-formatter.ts +++ b/src/formatting/formatters/v2-xml-formatter.ts @@ -20,7 +20,7 @@ export class V2XmlFormatter implements XmlFormatter { xml = xml.replace(/"\s+(?=[^\s]+=)/g, "\" "); // spaces between attributes xml = xml.replace(/"\s+(?=>)/g, "\""); // spaces between the last attribute and tag close (>) xml = xml.replace(/"\s+(?=\/>)/g, "\" "); // spaces between the last attribute and tag close (/>) - xml = xml.replace(/[^ <>="]\s+[^ <>="]+=/g, (match: string) => { // spaces between the node name and the first attribute + xml = xml.replace(/(?!="]\s+[^ <>="]+=(?![^<]*?\]\]>)/g, (match: string) => { // spaces between the node name and the first attribute return match.replace(/\s+/g, " "); }); diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 8c3627b..675aa6b 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -92,6 +92,9 @@ describe("V2XmlFormatter", () => { testFormatter(xmlFormatter, options, "issue-200"); }); + it("should not remove spaces between the node name and the first attribute within CDATA", () => { + testFormatter(xmlFormatter, options, "issue-227"); + }); }); }); diff --git a/src/test/test-data/issue-227.formatted.xml b/src/test/test-data/issue-227.formatted.xml new file mode 100644 index 0000000..d4ead94 --- /dev/null +++ b/src/test/test-data/issue-227.formatted.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/src/test/test-data/issue-227.unformatted.xml b/src/test/test-data/issue-227.unformatted.xml new file mode 100644 index 0000000..b55e3f3 --- /dev/null +++ b/src/test/test-data/issue-227.unformatted.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file