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

Commit 41d016b

Browse files
Gedalia Kottgedkott
authored andcommitted
Fixes URLs with query strings and hashes in them
The previous fix did not test a corner case where the user passes extensions allowed in the options. When there are no otpions passed for extensions allowed the extension check is skipped and thus the file is processed appropriately. I added virtual copies of the tests so feel free to point me to a better way of doing that. I just don't know what a better way to do it is without overwriting the original tests. The fix I made was stripping query strings and hashes from the regex results before the extension check and then passing in that stripped version into the check instead of the actual result which has the hash and/or query string.
1 parent 659860b commit 41d016b

File tree

2 files changed

+435
-273
lines changed

2 files changed

+435
-273
lines changed

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ function gulpCssBase64(opts) {
5858
return;
5959
}
6060

61-
if (opts.extensionsAllowed.length !== 0 && opts.extensionsAllowed.indexOf(path.extname(result[1])) === -1) {
61+
var pureURL = stripQueryStringFromURL(stripHashFromURL(result[1]));
62+
if (opts.extensionsAllowed.length !== 0 && opts.extensionsAllowed.indexOf(path.extname(pureURL)) === -1) {
6263
log('Ignores ' + chalk.yellow(result[1]) + ', extension not allowed ' + chalk.yellow(path.extname(result[1])), opts.verbose);
6364
callback();
6465
return;
@@ -190,5 +191,13 @@ function log(message, isVerbose) {
190191
}
191192
}
192193

194+
function stripQueryStringFromURL(urlString) {
195+
return urlString.split('?')[0];
196+
}
197+
198+
function stripHashFromURL(urlString) {
199+
return urlString.split('#')[0];
200+
}
201+
193202
// Exporting the plugin main function
194203
module.exports = gulpCssBase64;

0 commit comments

Comments
 (0)