Node on windows has path.sep set to '\'. This causes "urls" created with path.join() to be invalid. The fix is to use path.join() only for file/path manipulation, and url.resolve() for creating urls. I can confirm that this patch for buildSrcset() works, but my code doesn't exercise setSrcAttribute(). (All nodeunit tests fail on windows systems.)
--- tasks/responsive_images_extender.js 2016-06-05 08:36:50.673658300 -0700
+++ tasks/responsive_images_extender.js 2016-06-09 11:45:06.480446700 -0700
@@ -16,6 +16,7 @@
var fs = require('fs');
var path = require('path');
+ var url = require('url');
var cheerio = require('cheerio');
var sizeOf = require('image-size');
@@ -74,7 +75,9 @@
var candidate;
for (var img in srcMap) {
- candidate = path.join(path.dirname(imgSrc), img);
+ // path.join() creates invalid urls on systems where path.sep = '\\'
+ // candidate = path.join(path.dirname(imgSrc), img);
+ candidate = url.resolve(imgSrc, img);
if (width !== undefined) {
candidate += ' ' + Math.round(srcMap[img] / width * 100) / 100 + 'x';
}
@@ -118,7 +121,9 @@
}).reduce(function(a, b) {
return b[1] < a[1] ? b : a;
});
- imgElem.attr('src', path.join(path.dirname(imgSrc), smallestImage[0]));
+ // path.join() creates invalid urls on systems where path.sep = '\\'
+ // imgElem.attr('src', path.join(path.dirname(imgSrc), smallestImage[0]));
+ imgElem.attr('src', url.resolve(imgSrc, smallestImage[0]));
break;
default:
}