From 2ce106667165f13b4f0929a52e35d96761b2c613 Mon Sep 17 00:00:00 2001 From: Harris P Jose Date: Mon, 19 Feb 2018 10:48:15 +0530 Subject: [PATCH 1/2] Add failing test case for prefixIDs plugin When using the prefixIDs plugin on an svg with multiple linearGradients, url() values are not replaced correctly --- test/plugins/prefixIds.05.svg | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/plugins/prefixIds.05.svg diff --git a/test/plugins/prefixIds.05.svg b/test/plugins/prefixIds.05.svg new file mode 100644 index 000000000..d7805dd5d --- /dev/null +++ b/test/plugins/prefixIds.05.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + + + + + + + From 40987c96438706e5847d3275f1c64232774d3bb8 Mon Sep 17 00:00:00 2001 From: Harris P Jose Date: Mon, 19 Feb 2018 10:56:57 +0530 Subject: [PATCH 2/2] Fix issue with prefixIDs plugin not replacing url() values correctly Global regexs must be reseted after every exec call since they preserve the last matched index. Since we use `css-url-regex`, creating a new regex before `exec`ing fixes this. --- plugins/prefixIds.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/prefixIds.js b/plugins/prefixIds.js index ddda078fc..755baa65a 100644 --- a/plugins/prefixIds.js +++ b/plugins/prefixIds.js @@ -13,7 +13,7 @@ exports.description = 'prefix IDs'; var path = require('path'), csstree = require('css-tree'), - cssRx = require('css-url-regex')(), + cssRx = require('css-url-regex'), unquote = require('unquote'), collections = require('./_collections.js'), referencesProps = collections.referencesProps, @@ -37,7 +37,7 @@ var matchId = function(urlVal) { // Matches an url(...) value, captures the URL var matchUrl = function(val) { - var urlMatches = cssRx.exec(val); + var urlMatches = cssRx().exec(val); if (urlMatches === null) { return false; }