Commit 6e74c63a authored by Guy Tepper's avatar Guy Tepper

[FEATURE] improved url encoding

parent fc3e1505
...@@ -73,7 +73,7 @@ module.exports = function (_options) { ...@@ -73,7 +73,7 @@ module.exports = function (_options) {
// store this svg data // store this svg data
svgs.push({ svgs.push({
name: path.basename(file.path, '.svg'), 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', width: parseInt(width) + 'px',
height: parseInt(height) + 'px' height: parseInt(height) + 'px'
}); });
...@@ -90,5 +90,16 @@ module.exports = function (_options) { ...@@ -90,5 +90,16 @@ module.exports = function (_options) {
return callback(); 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); return through.obj(inlineSvg);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment