From 796776ed424420cfea6afa71be4c76661be9ef75 Mon Sep 17 00:00:00 2001 From: Hovhannes Babayan Date: Sun, 24 May 2020 12:43:01 +0400 Subject: [PATCH] feat: deprecate stripdeclarations option (closes #104) BREAKING CHANGE: stripdeclarations is now set to true by default. Previously was false by default. --- README.md | 3 +++ src/loader.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15083fdf..887cf9d4 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ require('svg-url-loader?prefix=img/!./file.svg'); ### `stripdeclarations` +This option is true by default. **It will be removed in the next major release.** +See [this issue](https://github.com/bhovhannes/svg-url-loader/issues/104#issuecomment-348377933) for more context about this decision. + If given will tell the loader to strip out any XML declaration, e.g. `` at the beginning of imported SVGs. Internet Explorer (tested in Edge 14) cannot handle XML declarations in CSS data URLs (`content: url("data:image/svg...")`). diff --git a/src/loader.js b/src/loader.js index a968e04e..5c722faf 100644 --- a/src/loader.js +++ b/src/loader.js @@ -24,9 +24,10 @@ module.exports = function(content) { var hasStyleElement = REGEX_STYLE.test(newContent) - if (query.stripdeclarations) { + if (!('stripdeclarations' in query) || query.stripdeclarations) { newContent = newContent.replace(REGEX_DECLARATION, ""); } + newContent = newContent.replace(REGEX_MULTIPLE_SPACES, " "); var data; if (query.encoding === "base64") { @@ -36,7 +37,6 @@ module.exports = function(content) { data = "data:image/svg+xml;base64," + newContent.toString("base64"); } else { newContent = newContent.replace(REGEX_DOUBLE_QUOTE, "'"); - newContent = newContent.replace(REGEX_MULTIPLE_SPACES, " "); newContent = newContent.replace(REGEX_UNSAFE_CHARS, function(match) { return '%'+match[0].charCodeAt(0).toString(16).toUpperCase(); });