From 6e74c63a8147e7380899286c26161f9544d47d73 Mon Sep 17 00:00:00 2001 From: Guy Tepper Date: Wed, 12 Oct 2016 13:39:29 +0300 Subject: [PATCH] [FEATURE] improved url encoding --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 22d0b49..a2bdc41 100644 --- a/index.js +++ b/index.js @@ -73,7 +73,7 @@ module.exports = function (_options) { // store this svg data svgs.push({ name: path.basename(file.path, '.svg'), - inline: 'data:image/svg+xml,' + encodeURIComponent(String(file.contents)), + inline: 'data:image/svg+xml,' + urlEncode(file.contents), width: parseInt(width) + 'px', height: parseInt(height) + 'px' }); @@ -90,5 +90,16 @@ module.exports = function (_options) { return callback(); } + function urlEncode(content) { + content = content.toString('utf8'); + content = content.replace(/"/g, "'"); + content = content.replace(/\s+/g, " "); + content = content.replace(/[{}\|\\\^~\[\]`"<>#%]/g, function(match) { + return '%'+match[0].charCodeAt(0).toString(16).toUpperCase(); + }); + + return 'data:image/svg+xml;charset=utf8,' + content.trim(); + } + return through.obj(inlineSvg); }; -- GitLab