Skip to content

Commit

Permalink
feat: deprecate stripdeclarations option (closes #104)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: stripdeclarations is now set to true by default. Previously was false by default.
  • Loading branch information
bhovhannes committed May 24, 2020
1 parent a79d848 commit 796776e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<?xml version="1.0" encoding="UTF-8"?>` 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...")`).

Expand Down
4 changes: 2 additions & 2 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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();
});
Expand Down

0 comments on commit 796776e

Please sign in to comment.