diff --git a/src/index.js b/src/index.js index 3cbd70c..92b163d 100644 --- a/src/index.js +++ b/src/index.js @@ -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; diff --git a/test/test.js b/test/test.js index 85e0346..7970fb3 100644 --- a/test/test.js +++ b/test/test.js @@ -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({ @@ -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({