Skip to content

Commit

Permalink
Merge pull request #2549 from mockee/dev
Browse files Browse the repository at this point in the history
Bug fixes of encoding png image in `url` lib function
  • Loading branch information
xdan committed Aug 18, 2020
2 parents 8f42760 + 96c02de commit 59bc665
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/functions/url.js
Expand Up @@ -114,19 +114,19 @@ module.exports = function(options) {
}

// Read data
var str = fs.readFileSync(found, 'utf8');
buf = fs.readFileSync(found);

// Too large
if(false !== sizeLimit && str.length > sizeLimit) return literal;
if(false !== sizeLimit && buf.length > sizeLimit) return literal;

if(enc && 'utf8' == enc.first.val.toLowerCase()) {
encoding = encodingTypes.UTF8;
result = str.replace(/\s+/g, ' ')
result = buf.toString().replace(/\s+/g, ' ')
.replace(/[{}\|\\\^~\[\]`"<>#%]/g, function(match) {
return '%' + match[0].charCodeAt(0).toString(16).toUpperCase();
}).trim();
} else {
result = Buffer.from(str.replace(/\r\n?/g, '\n')).toString(encoding) + hash;
result = buf.toString(encoding) + hash;
}

// Encode
Expand Down

0 comments on commit 59bc665

Please sign in to comment.