Skip to content

Commit

Permalink
Handle escaped characters in image file names, fixes 247even#7.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristim committed Oct 11, 2016
1 parent cf10cbb commit e911532
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function() {
var mtype = mime.lookup(spath);
if (mtype != 'application/octet-stream') {
console.log(mtype);
var sfile = fs.readFileSync(spath);
var sfile = fs.readFileSync(unescape(spath));
var simg64 = new Buffer(sfile).toString('base64');
this.attr('src', 'data:' + mtype + ';base64,' + simg64);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/fixtures/input with spaces in filename.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<body>
<img src="directory%20with%20spaces/clock%20with%20escaped%20spaces%20in%20filename.png" />
</body>
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,28 @@ describe('gulp-img64', function() {

});

it('should support escaped characters in image file names', function(done) {

var filename = path.join(__dirname, '/fixtures/input with spaces in filename.html');

var input = new gutil.File({
base: path.dirname(filename),
path: filename,
contents: new Buffer(fs.readFileSync(filename, 'utf8'))
});

var stream = img64();

stream.on('data', function(newFile) {
assert.equal(String(newFile.contents), fs.readFileSync(path.join(__dirname, '/fixtures/output.html'), 'utf8'));
done();
});

stream.write(input);

});



});
});

0 comments on commit e911532

Please sign in to comment.