From e188f440c4489d0ec60cd5add0ae4b7142c2bd83 Mon Sep 17 00:00:00 2001 From: Matthew Dean Date: Thu, 16 Jul 2020 07:31:03 -0700 Subject: [PATCH] Fixes #3541 (#3543) --- .../less/src/less-node/url-file-manager.js | 21 ++++++++----------- .../test-data/css/_main/import-remote.css | 3 +++ .../test-data/less/_main/import-remote.less | 8 +++++++ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 packages/test-data/css/_main/import-remote.css create mode 100644 packages/test-data/less/_main/import-remote.less diff --git a/packages/less/src/less-node/url-file-manager.js b/packages/less/src/less-node/url-file-manager.js index 09558bc31..733d78c86 100644 --- a/packages/less/src/less-node/url-file-manager.js +++ b/packages/less/src/less-node/url-file-manager.js @@ -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 }); }); diff --git a/packages/test-data/css/_main/import-remote.css b/packages/test-data/css/_main/import-remote.css new file mode 100644 index 000000000..23ef8dbcc --- /dev/null +++ b/packages/test-data/css/_main/import-remote.css @@ -0,0 +1,3 @@ +.test { + color: blue; +} diff --git a/packages/test-data/less/_main/import-remote.less b/packages/test-data/less/_main/import-remote.less new file mode 100644 index 000000000..6e2a947cf --- /dev/null +++ b/packages/test-data/less/_main/import-remote.less @@ -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; +} \ No newline at end of file