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