From 4739b52f6bbcbef60f3989eade7311237dcead67 Mon Sep 17 00:00:00 2001 From: Daniel Schreiber Date: Thu, 10 Mar 2022 10:56:06 +0100 Subject: [PATCH] fix: handle xml declaration without new line --- .github/workflows/node.js.yml | 4 ++-- __tests__/xmlNormalize.test.ts | 4 ++++ src/xmlNormalize.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index e225815..e0026fd 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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: @@ -42,4 +42,4 @@ jobs: uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true \ No newline at end of file + parallel-finished: true diff --git a/__tests__/xmlNormalize.test.ts b/__tests__/xmlNormalize.test.ts index 1c78902..504f65e 100644 --- a/__tests__/xmlNormalize.test.ts +++ b/__tests__/xmlNormalize.test.ts @@ -7,6 +7,10 @@ describe('xmlNormalize', () => { expect(xmlNormalize({...defaultOptions, in: 'texttext2'})) .toEqual('texttext2'); }); + test('handle xml declaration without new line', () => { + expect(xmlNormalize({...defaultOptions, in: 'texttext2'})) + .toEqual('texttext2'); + }); describe('sort', () => { test('simple sort', () => { diff --git a/src/xmlNormalize.ts b/src/xmlNormalize.ts index 0de95c1..33baf7f 100644 --- a/src/xmlNormalize.ts +++ b/src/xmlNormalize.ts @@ -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});