Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3541 #3543

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}