From 4b4259bc604d008d17098a1b7a22eb9d757d16d3 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 23 Feb 2021 22:49:28 +0300 Subject: [PATCH] Fix parsing xml entities (#1371) Ref https://github.com/svg/sax/releases/tag/v0.1.1 This fixes enother case in [regression tests](https://github.com/svg/svgo/pull/1357). --- package-lock.json | 6 +++--- package.json | 2 +- test/svg2js/_index.js | 28 ---------------------------- test/svg2js/test.entities.svg | 8 -------- test/svgo/_index.js | 5 +++++ test/svgo/entities.svg | 29 +++++++++++++++++++++++++++++ 6 files changed, 38 insertions(+), 40 deletions(-) delete mode 100644 test/svg2js/test.entities.svg create mode 100644 test/svgo/entities.svg diff --git a/package-lock.json b/package-lock.json index b4f946df0..bd4f62939 100644 --- a/package-lock.json +++ b/package-lock.json @@ -180,9 +180,9 @@ } }, "@trysound/sax": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.1.0.tgz", - "integrity": "sha512-1yH66Pny121c7ZwLW/zLedcflwPHELEg4pMo6pA+U1PoEKt8hUI6SKD47mfAJhC+4IExoEr0tMTYETlhpjPhmQ==" + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.1.1.tgz", + "integrity": "sha512-Z6DoceYb/1xSg5+e+ZlPZ9v0N16ZvZ+wYMraFue4HYrE4ttONKtsvruIRf6t9TBR0YvSOfi1hUU0fJfBLCDYow==" }, "@types/estree": { "version": "0.0.39", diff --git a/package.json b/package.json index 4bffd3dc7..8e5f0cbba 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ ] }, "dependencies": { - "@trysound/sax": "0.1.0", + "@trysound/sax": "0.1.1", "chalk": "^4.1.0", "commander": "^7.1.0", "css-select": "^3.1.2", diff --git a/test/svg2js/_index.js b/test/svg2js/_index.js index 3a61eb143..8aca4e455 100644 --- a/test/svg2js/_index.js +++ b/test/svg2js/_index.js @@ -457,32 +457,4 @@ describe('svg2js', function() { }); }); - - describe('entities', function() { - var filepath = PATH.resolve(__dirname, './test.entities.svg'), - root; - - before(function(done) { - FS.readFile(filepath, 'utf8', function(err, data) { - if (err) throw err; - - root = SVG2JS(data); - done(); - }); - }); - - describe('root', function() { - it('should exist', function() { - expect(root).to.exist; - }); - - it('should have correctly parsed entities', function() { - var attrs = root.content[root.content.length - 1].attrs; - - expect(attrs['xmlns:x'].value).to.be.equal('http://ns.adobe.com/Extensibility/1.0/'); - expect(attrs['xmlns:graph'].value).to.be.equal('http://ns.adobe.com/Graphs/1.0/'); - }); - }); - }); - }); diff --git a/test/svg2js/test.entities.svg b/test/svg2js/test.entities.svg deleted file mode 100644 index 03e4d43c0..000000000 --- a/test/svg2js/test.entities.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - -]> - \ No newline at end of file diff --git a/test/svgo/_index.js b/test/svgo/_index.js index 5ee20fcde..4d5d9d4ae 100644 --- a/test/svgo/_index.js +++ b/test/svgo/_index.js @@ -66,4 +66,9 @@ describe('svgo', () => { const result = optimize(original, { input: 'file', path: 'input.svg', js2svg: { pretty: true } }); expect(normalize(result.data)).to.equal(expected); }); + it('should inline entities', async () => { + const [original, expected] = await parseFixture('entities.svg'); + const result = optimize(original, { path: 'input.svg', plugins: [], js2svg: { pretty: true } }); + expect(normalize(result.data)).to.equal(expected); + }); }); diff --git a/test/svgo/entities.svg b/test/svgo/entities.svg new file mode 100644 index 000000000..cc85db37c --- /dev/null +++ b/test/svgo/entities.svg @@ -0,0 +1,29 @@ + + + + + +"> +]> + + + &Viewport; + + + +@@@ + + + + + + +"> +]> + + + + +