Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function gulpCssBase64(opts) {
return;
}

if (opts.extensionsAllowed.length !== 0 && opts.extensionsAllowed.indexOf(path.extname(result[1])) === -1) {
var pureUrl = result[1].split('?')[0].split('#')[0];
if (opts.extensionsAllowed.length !== 0 && opts.extensionsAllowed.indexOf(path.extname(pureUrl)) === -1) {
log('Ignores ' + chalk.yellow(result[1]) + ', extension not allowed ' + chalk.yellow(path.extname(result[1])), opts.verbose);
callback();
return;
Expand Down
50 changes: 50 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ describe('gulp-css-base64', function () {
});
});

it('should convert url() content with questionmark at end even if extensionsAllowed is passed', function (done) {
// create the fake file
var fakeFile = new gutil.File({
contents: new Buffer('.button_alert{background:url(\'test/fixtures/image/very-very-small.png?awesomeQuestionmark\') no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}')
});

// Create a css-base64 plugin stream
var stream = base64({
extensionsAllowed: ['.gif', '.jpg', '.png']
});

// write the fake file to it
stream.write(fakeFile);

// wait for the file to come back out
stream.once('data', function (file) {
// make sure it came out the same way it went in
assert(file.isBuffer());

// check the contents
assert.equal(file.contents.toString('utf8'), '.button_alert{background:url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANAQAAAABakNnRAAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAArSURBVAjXY/j/g2H/C4b5Jxj6OxgaOEBoxgmGDg8GIACyuRoYjkowfKgAACBpDLQ2kvRRAAAAAElFTkSuQmCC\') no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}');
done();
});
});

it('should convert url() content with hashtag at end', function (done) {
// create the fake file
var fakeFile = new gutil.File({
Expand All @@ -138,6 +163,31 @@ describe('gulp-css-base64', function () {
});
});

it('should convert url() content with hashtag at end even if extensionsAllowed is passed', function (done) {
// create the fake file
var fakeFile = new gutil.File({
contents: new Buffer('.button_alert{background:url(\'test/fixtures/image/very-very-small.png#awesomeHashtag\') no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}')
});

// Create a css-base64 plugin stream
var stream = base64({
extensionsAllowed: ['.gif', '.jpg', '.png']
});

// write the fake file to it
stream.write(fakeFile);

// wait for the file to come back out
stream.once('data', function (file) {
// make sure it came out the same way it went in
assert(file.isBuffer());

// check the contents
assert.equal(file.contents.toString('utf8'), '.button_alert{background:url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANAQAAAABakNnRAAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAArSURBVAjXY/j/g2H/C4b5Jxj6OxgaOEBoxgmGDg8GIACyuRoYjkowfKgAACBpDLQ2kvRRAAAAAElFTkSuQmCC\') no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}');
done();
});
});

it('should ignore if image weight is greater than maxWeightResource default value', function (done) {
// create the fake file
var fakeFile = new gutil.File({
Expand Down