Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.

Commit a71d899

Browse files
author
Mehdy Dara
committed
Merge pull request #23 from zckrs/fix-questionmark-hashtag
Remove hashtag/questionmark before get location of file
2 parents 4c8d6d9 + ac6db6a commit a71d899

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gulp-css-base64",
33
"description": "Gulp's task for transform all resources found in a CSS into base64-encoded data URI strings",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"homepage": "http://github.com/zckrs/gulp-css-base64",
66
"repository": {
77
"type": "git",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function encodeResource(img, file, opts, doneCallback) {
141141
var binRes = '';
142142

143143
location = img.charAt(0) === '/' ? (opts.baseDir || '') + img : path.join(path.dirname(file.path), (opts.baseDir || '') + '/' + img);
144+
location = location.replace(/([?#].*)$/, "");
144145

145146
if (!fs.existsSync(location)) {
146147
log('Error: ' + chalk.red(location) + ', file not found', opts.verbose);

test/test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,52 @@ describe('gulp-css-base64', function () {
8585
});
8686
});
8787

88+
it('should convert url() content with questionmark at end', function (done) {
89+
// create the fake file
90+
var fakeFile = new gutil.File({
91+
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}')
92+
});
93+
94+
// Create a css-base64 plugin stream
95+
var stream = base64();
96+
97+
// write the fake file to it
98+
stream.write(fakeFile);
99+
100+
// wait for the file to come back out
101+
stream.once('data', function (file) {
102+
// make sure it came out the same way it went in
103+
assert(file.isBuffer());
104+
105+
// check the contents
106+
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}');
107+
done();
108+
});
109+
});
110+
111+
it('should convert url() content with hashtag at end', function (done) {
112+
// create the fake file
113+
var fakeFile = new gutil.File({
114+
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}')
115+
});
116+
117+
// Create a css-base64 plugin stream
118+
var stream = base64();
119+
120+
// write the fake file to it
121+
stream.write(fakeFile);
122+
123+
// wait for the file to come back out
124+
stream.once('data', function (file) {
125+
// make sure it came out the same way it went in
126+
assert(file.isBuffer());
127+
128+
// check the contents
129+
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}');
130+
done();
131+
});
132+
});
133+
88134
it('should ignore if image weight is greater than maxWeightResource default value', function (done) {
89135
// create the fake file
90136
var fakeFile = new gutil.File({

0 commit comments

Comments
 (0)