Skip to content

Commit

Permalink
inline loaderUtils.isUrlRequest given new behaviour >=3.0.0 is unsuit…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
bholloway committed Oct 14, 2022
1 parent 0ce3b17 commit 835d3df
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/resolve-url-loader/lib/value-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
var path = require('path'),
loaderUtils = require('loader-utils');

/**
* We require the lost functionality from loaderUtils.isUrlRequest()@>=3.0.0
* https://github.com/webpack/loader-utils/blob/47d0be719a8243e7805e8070fcec857427529508/lib/isUrlRequest.js
*/
function isUrlRequest(url, root) {
// An URL is not an request if

// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
return true; // ALLOWED;
}

// 2. It's a protocol-relative
if (/^\/\//.test(url)) {
return false;
}

// 3. It's some kind of url for a template
if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.test(url)) {
return false;
}

// 4. It's also not an request if root isn't set and it's a root-relative url
if ((root === undefined || root === false) && /^\//.test(url)) {
return false;
}

return true;
}

/**
* Create a value processing function for a given file path.
*
Expand Down Expand Up @@ -117,7 +147,7 @@ function valueProcessor({ join, root, directory }) {
* @return {boolean} True for relative uri
*/
function testIsRelative(uri) {
return !!uri && loaderUtils.isUrlRequest(uri, false) && !path.isAbsolute(uri) && (uri.indexOf('~') !== 0);
return !!uri && isUrlRequest(uri, false) && !path.isAbsolute(uri) && (uri.indexOf('~') !== 0);
}

/**
Expand All @@ -128,7 +158,7 @@ function valueProcessor({ join, root, directory }) {
* @return {boolean} True for absolute uri
*/
function testIsAbsolute(uri) {
return !!uri && (typeof root === 'string') && loaderUtils.isUrlRequest(uri, root) &&
return !!uri && (typeof root === 'string') && isUrlRequest(uri, root) &&
(/^\//.test(uri) || path.isAbsolute(uri));
}
}
Expand Down

0 comments on commit 835d3df

Please sign in to comment.