From 46b333dcff5a43f23d824fb5efc686a3307f9d74 Mon Sep 17 00:00:00 2001 From: strarsis Date: Sun, 6 Sep 2020 17:18:44 +0200 Subject: [PATCH] Replace sax library with saxes library. Increase test (mocha) timeout to 10s, as the tests currently run longer with saxes. --- bin/svgo | 0 lib/svgo.js | 0 lib/svgo/svg2js.js | 28 ++++++++++++++-------------- package-lock.json | 16 ++++++++++++---- package.json | 4 ++-- plugins/minifyStyles.js | 0 plugins/prefixIds.js | 0 test/plugins/minifyStyles.01.svg | 0 test/plugins/minifyStyles.10.svg | 0 9 files changed, 28 insertions(+), 20 deletions(-) mode change 100755 => 100644 bin/svgo mode change 100755 => 100644 lib/svgo.js mode change 100755 => 100644 plugins/minifyStyles.js mode change 100755 => 100644 plugins/prefixIds.js mode change 100755 => 100644 test/plugins/minifyStyles.01.svg mode change 100755 => 100644 test/plugins/minifyStyles.10.svg diff --git a/bin/svgo b/bin/svgo old mode 100755 new mode 100644 diff --git a/lib/svgo.js b/lib/svgo.js old mode 100755 new mode 100644 diff --git a/lib/svgo/svg2js.js b/lib/svgo/svg2js.js index 6bba13e58..848c45c6e 100644 --- a/lib/svgo/svg2js.js +++ b/lib/svgo/svg2js.js @@ -1,6 +1,6 @@ 'use strict'; -var SAX = require('sax'), +var SAXES = require('saxes'), JSAPI = require('./jsAPI.js'), CSSClassList = require('./css-class-list'), CSSStyleDeclaration = require('./css-style-declaration'), @@ -23,7 +23,7 @@ var config = { */ module.exports = function(data, callback) { - var sax = SAX.parser(config.strict, config), + var saxes = new SAXES.SaxesParser(config.strict, config), root = new JSAPI({ elem: '#document', content: [] }), current = root, stack = [root], @@ -40,7 +40,7 @@ module.exports = function(data, callback) { } - sax.ondoctype = function(doctype) { + saxes.ondoctype = function(doctype) { pushToContent({ doctype: doctype @@ -53,12 +53,12 @@ module.exports = function(data, callback) { entityDeclaration.lastIndex = subsetStart; while ((entityMatch = entityDeclaration.exec(data)) != null) { - sax.ENTITIES[entityMatch[1]] = entityMatch[2] || entityMatch[3]; + saxes.ENTITIES[entityMatch[1]] = entityMatch[2] || entityMatch[3]; } } }; - sax.onprocessinginstruction = function(data) { + saxes.onprocessinginstruction = function(data) { pushToContent({ processinginstruction: data @@ -66,7 +66,7 @@ module.exports = function(data, callback) { }; - sax.oncomment = function(comment) { + saxes.oncomment = function(comment) { pushToContent({ comment: comment.trim() @@ -74,7 +74,7 @@ module.exports = function(data, callback) { }; - sax.oncdata = function(cdata) { + saxes.oncdata = function(cdata) { pushToContent({ cdata: cdata @@ -82,7 +82,7 @@ module.exports = function(data, callback) { }; - sax.onopentag = function(data) { + saxes.onopentag = function(data) { var elem = { elem: data.name, @@ -126,7 +126,7 @@ module.exports = function(data, callback) { }; - sax.ontext = function(text) { + saxes.ontext = function(text) { if (/\S/.test(text) || textContext) { @@ -141,7 +141,7 @@ module.exports = function(data, callback) { }; - sax.onclosetag = function() { + saxes.onclosetag = function() { var last = stack.pop(); @@ -154,7 +154,7 @@ module.exports = function(data, callback) { }; - sax.onerror = function(e) { + saxes.onerror = function(e) { e.message = 'Error in parsing SVG: ' + e.message; if (e.message.indexOf('Unexpected end') < 0) { @@ -163,7 +163,7 @@ module.exports = function(data, callback) { }; - sax.onend = function() { + saxes.onend = function() { if (!this.error) { callback(root); @@ -174,12 +174,12 @@ module.exports = function(data, callback) { }; try { - sax.write(data); + saxes.write(data); } catch (e) { callback({ error: e.message }); parsingError = true; } - if (!parsingError) sax.close(); + if (!parsingError) saxes.close(); function trim(elem) { if (!elem.content) return elem; diff --git a/package-lock.json b/package-lock.json index b83f54d95..74b851c19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1412,10 +1412,13 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + "saxes": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz", + "integrity": "sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==", + "requires": { + "xmlchars": "^2.2.0" + } }, "semver": { "version": "5.7.1", @@ -1751,6 +1754,11 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" + }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", diff --git a/package.json b/package.json index 4f4f18267..587fa59a8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "example": "./examples" }, "scripts": { - "test": "set NODE_ENV=test && mocha", + "test": "set NODE_ENV=test && mocha --timeout 10000", "lint": "jshint --show-non-errors .", "jshint": "npm run lint" }, @@ -57,7 +57,7 @@ "js-yaml": "^3.13.1", "mkdirp": "~0.5.1", "object.values": "^1.1.0", - "sax": "~1.2.4", + "saxes": "^5.0.1", "stable": "^0.1.8", "unquote": "~1.1.1", "util.promisify": "~1.0.0" diff --git a/plugins/minifyStyles.js b/plugins/minifyStyles.js old mode 100755 new mode 100644 diff --git a/plugins/prefixIds.js b/plugins/prefixIds.js old mode 100755 new mode 100644 diff --git a/test/plugins/minifyStyles.01.svg b/test/plugins/minifyStyles.01.svg old mode 100755 new mode 100644 diff --git a/test/plugins/minifyStyles.10.svg b/test/plugins/minifyStyles.10.svg old mode 100755 new mode 100644