From 0cc71c7cc98628c52dfeef0d7e1d16f11569ad6f Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 8 Jul 2020 22:22:11 -0400 Subject: [PATCH 1/2] Add Failing Test --- src/test/extension.test.ts | 4 ++++ src/test/test-data/issue-288.formatted.xml | 11 +++++++++++ src/test/test-data/issue-288.unformatted.xml | 11 +++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/test/test-data/issue-288.formatted.xml create mode 100644 src/test/test-data/issue-288.unformatted.xml diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 31f44e7..dc4e04d 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -103,6 +103,10 @@ describe("V2XmlFormatter", () => { it("should not touch CDATA content", () => { testFormatter(xmlFormatter, options, "issue-293"); }); + + it("should not add trailing whitespace", () => { + testFormatter(xmlFormatter, options, "issue-288"); + }); }); describe("#minifyXml(xml, options)", () => { diff --git a/src/test/test-data/issue-288.formatted.xml b/src/test/test-data/issue-288.formatted.xml new file mode 100644 index 0000000..8231c91 --- /dev/null +++ b/src/test/test-data/issue-288.formatted.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/src/test/test-data/issue-288.unformatted.xml b/src/test/test-data/issue-288.unformatted.xml new file mode 100644 index 0000000..8231c91 --- /dev/null +++ b/src/test/test-data/issue-288.unformatted.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file From d4bf60d282d228b7b2d72722f75520d845afdb6b Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 8 Jul 2020 23:08:56 -0400 Subject: [PATCH 2/2] Trim Trailing Whitespace from Split Attributes fixes #288 --- src/formatting/formatters/v2-xml-formatter.ts | 4 ++++ src/test/test-data/issue-189.formatted.xml | 2 +- src/test/test-data/issue-257.formatted.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/formatting/formatters/v2-xml-formatter.ts b/src/formatting/formatters/v2-xml-formatter.ts index 8b0fcbb..281f631 100644 --- a/src/formatting/formatters/v2-xml-formatter.ts +++ b/src/formatting/formatters/v2-xml-formatter.ts @@ -163,6 +163,10 @@ export class V2XmlFormatter implements XmlFormatter { && ((options.splitXmlnsOnFormat && xml.substr(i, 5).toLowerCase() === "xmlns") || options.splitAttributesOnFormat)) { + + // trim the end of output here to ensure there is no trailing whitespace (issue #288) + output = this._removeTrailingNonBreakingWhitespace(output); + output += `${options.newLine}${this._getIndent(options, indentLevel)}`; } diff --git a/src/test/test-data/issue-189.formatted.xml b/src/test/test-data/issue-189.formatted.xml index b3a3d19..952ff72 100644 --- a/src/test/test-data/issue-189.formatted.xml +++ b/src/test/test-data/issue-189.formatted.xml @@ -1,5 +1,5 @@ - \ No newline at end of file diff --git a/src/test/test-data/issue-257.formatted.xml b/src/test/test-data/issue-257.formatted.xml index 842df62..7cfe79e 100644 --- a/src/test/test-data/issue-257.formatted.xml +++ b/src/test/test-data/issue-257.formatted.xml @@ -1,5 +1,5 @@ -