Skip to content

Commit

Permalink
Fixes #227
Browse files Browse the repository at this point in the history
  • Loading branch information
emericklaw committed Sep 6, 2018
1 parent 84adff5 commit 664760c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/formatting/formatters/v2-xml-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?!<!\[CDATA\[)[^ <>="]\s+[^ <>="]+=(?![^<]*?\]\]>)/g, (match: string) => { // spaces between the node name and the first attribute
return match.replace(/\s+/g, " ");
});

Expand Down
3 changes: 3 additions & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

});
Expand Down
19 changes: 19 additions & 0 deletions src/test/test-data/issue-227.formatted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Job>
<SQLQuery test="">
<SQLSelect Test="test" test="test">
<![CDATA[
select
*
from test
where
aaa.aaa='AAA' and
isnull(BBB.BBB,0)=0 and
isnull(CCTestC.CCC,0)=1 and
DDD.DDD is null and
exists (select 1 from EEE where EEE.EEE=EEE.EEE and EEE is null) and
exists (select 1 from FFF where FFF.FFF=FFF.FFF) and
'{GGG}' like '%'+GGG.GGG+'%'
]]>
</SQLSelect>
</SQLQuery>
</Job>
19 changes: 19 additions & 0 deletions src/test/test-data/issue-227.unformatted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Job>
<SQLQuery test="">
<SQLSelect Test="test" test="test">
<![CDATA[
select
*
from test
where
aaa.aaa='AAA' and
isnull(BBB.BBB,0)=0 and
isnull(CCTestC.CCC,0)=1 and
DDD.DDD is null and
exists (select 1 from EEE where EEE.EEE=EEE.EEE and EEE is null) and
exists (select 1 from FFF where FFF.FFF=FFF.FFF) and
'{GGG}' like '%'+GGG.GGG+'%'
]]>
</SQLSelect>
</SQLQuery>
</Job>

0 comments on commit 664760c

Please sign in to comment.