Skip to content

Commit

Permalink
fix: handle xml declaration without new line
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Mar 10, 2022
1 parent 7c1fded commit 4739b52
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -42,4 +42,4 @@ jobs:
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
parallel-finished: true
4 changes: 4 additions & 0 deletions __tests__/xmlNormalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ describe('xmlNormalize', () => {
expect(xmlNormalize({...defaultOptions, in: '<root><node>text</node><node>text2</node></root>'}))
.toEqual('<root><node>text</node><node>text2</node></root>');
});
test('handle xml declaration without new line', () => {
expect(xmlNormalize({...defaultOptions, in: '<?xml version="1.0"?><root><node>text</node><node>text2</node></root>'}))
.toEqual('<?xml version="1.0"?><root><node>text</node><node>text2</node></root>');
});

describe('sort', () => {
test('simple sort', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/xmlNormalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function xmlNormalize(options: XmlNormalizeOptions) {
doc = pretty(doc);
}

const xmlDecMatch = options.in.match(/^<\?xml .*[^>]\s*/i);
const xmlDecMatch = options.in.match(/^<\?xml [^>]*>\s*/i);
const xmlDeclaration = xmlDecMatch ? xmlDecMatch[0] : '';

return xmlDeclaration + doc.toString({preserveWhitespace: true, compressed: true});
Expand Down

0 comments on commit 4739b52

Please sign in to comment.