Skip to content

Commit ddfd1ca

Browse files
committed
Fix #1987. First, res may be null if we have an error with a URL. Second, if the URL has no protocol, use http
1 parent 6745058 commit ddfd1ca

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/less/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,23 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
175175
var urlStr = isUrl ? file : url.resolve(currentFileInfo.currentDirectory, file),
176176
urlObj = url.parse(urlStr);
177177

178+
if (!urlObj.protocol) {
179+
urlObj.protocol = "http";
180+
urlStr = urlObj.format();
181+
}
182+
178183
request.get({uri: urlStr, strictSSL: !env.insecure }, function (error, res, body) {
184+
if (error) {
185+
callback({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n "+ error +"\n" });
186+
return;
187+
}
179188
if (res.statusCode === 404) {
180189
callback({ type: 'File', message: "resource '" + urlStr + "' was not found\n" });
181190
return;
182191
}
183192
if (!body) {
184193
console.error( 'Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr +'"' );
185194
}
186-
if (error) {
187-
callback({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n "+ error +"\n" });
188-
}
189195
pathname = urlStr;
190196
dirname = urlObj.protocol +'//'+ urlObj.host + urlObj.pathname.replace(/[^\/]*$/, '');
191197
handleDataAndCallCallback(body);

0 commit comments

Comments
 (0)