diff --git a/index.js b/index.js index 37c97ca..0630e2b 100644 --- a/index.js +++ b/index.js @@ -67,8 +67,14 @@ module.exports = function (options) { function resolveDataUrl(assetStr) { var resolvedPath = resolvePath(assetStr); var mimeType = mime.lookup(resolvedPath); - var data = base64.encode(fs.readFileSync(resolvedPath)); - return 'data:' + mimeType + ';base64,' + data; + if (mimeType === 'image/svg+xml') { + var data = cssesc(fs.readFileSync(resolvedPath).toString()); + var encoding = 'utf8'; + } else { + data = base64.encode(fs.readFileSync(resolvedPath)); + encoding = 'base64'; + } + return 'data:' + mimeType + ';' + encoding + ',' + data; } function resolvePath(assetStr) { diff --git a/package.json b/package.json index 45f3150..0bc6c07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-assets", - "version": "0.9.0", + "version": "0.9.1", "description": "PostCSS plugin to manage assets", "author": "Vadim Borodean ", "license": "MIT", diff --git a/test/fixtures/alpha/trapezium-single-quotes.svg b/test/fixtures/alpha/trapezium-single-quotes.svg new file mode 100644 index 0000000..84a4d86 --- /dev/null +++ b/test/fixtures/alpha/trapezium-single-quotes.svg @@ -0,0 +1,3 @@ + + + diff --git a/test/fixtures/alpha/trapezium.svg b/test/fixtures/alpha/trapezium.svg new file mode 100644 index 0000000..b65440b --- /dev/null +++ b/test/fixtures/alpha/trapezium.svg @@ -0,0 +1,3 @@ + + + diff --git a/test/fixtures/inline.css b/test/fixtures/inline.css index 2047d71..f188033 100644 --- a/test/fixtures/inline.css +++ b/test/fixtures/inline.css @@ -2,4 +2,6 @@ body { background: url('alpha/blank.gif'); background: url( 'alpha/blank.gif' ); background: url('alpha/kateryna.jpg'); + background: url('alpha/trapezium.svg'); + background: url('alpha/trapezium-single-quotes.svg'); } diff --git a/test/fixtures/inline.expected.css b/test/fixtures/inline.expected.css index 88e7e9a..0bdff64 100644 --- a/test/fixtures/inline.expected.css +++ b/test/fixtures/inline.expected.css @@ -2,4 +2,6 @@ body { background: url('data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='); background: url( 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==' ); background: url('/alpha/kateryna.jpg'); + background: url('data:image/svg+xml;utf8,\D\A \D\A\D\A'); + background: url('data:image/svg+xml;utf8,\D\A \D\A\D\A'); }