Skip to content

Commit

Permalink
Fixes #3541 (#3543)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean authored Jul 16, 2020
1 parent 2870163 commit e188f44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/less/src/less-node/url-file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,21 @@ class UrlFileManager extends AbstractFileManager {
}

let urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename);
const urlObj = url.parse(urlStr);

/** native-request currently has a bug */
const hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr

if (!urlObj.protocol) {
urlObj.protocol = 'http';
urlStr = urlObj.format();
}

request.get({uri: urlStr, strictSSL: !options.insecure }, (error, res, body) => {
if (error) {
reject({ type: 'File', message: `resource '${urlStr}' gave this Error:\n ${error}\n` });
request.get(hackUrlStr, (error, body, status) => {
if (status === 404) {
reject({ type: 'File', message: `resource '${urlStr}' was not found\n` });
return;
}
if (res && res.statusCode === 404) {
reject({ type: 'File', message: `resource '${urlStr}' was not found\n` });
if (error) {
reject({ type: 'File', message: `resource '${urlStr}' gave this Error:\n ${error}\n` });
return;
}
if (!body) {
logger.warn(`Warning: Empty body (HTTP ${res.statusCode}) returned by "${urlStr}"`);
logger.warn(`Warning: Empty body (HTTP ${status}) returned by "${urlStr}"`);
}
fulfill({ contents: body, filename: urlStr });
});
Expand Down
3 changes: 3 additions & 0 deletions packages/test-data/css/_main/import-remote.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test {
color: blue;
}
8 changes: 8 additions & 0 deletions packages/test-data/less/_main/import-remote.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://github.com/less/less.js/issues/3541
@import (reference) url(https://cdn.jsdelivr.net/npm/@less/test-data/less/_main/selectors.less);
@import (reference) url("https://cdn.jsdelivr.net/npm/@less/test-data/less/_main/scope.less");
@import (reference) url("https://cdn.jsdelivr.net/npm/@less/test-data/less/_main/empty.less?arg");

.test {
color: @x;
}

0 comments on commit e188f44

Please sign in to comment.