Skip to content

Commit 03b38ad

Browse files
committed
inline loaderUtils.isUrlRequest given new behaviour >=3.0.0 is unsuitable
1 parent 0ce3b17 commit 03b38ad

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

packages/resolve-url-loader/lib/value-processor.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@
77
var path = require('path'),
88
loaderUtils = require('loader-utils');
99

10+
/**
11+
* We require the lost functionality from loaderUtils.isUrlRequest()@>=3.0.0
12+
* https://github.com/webpack/loader-utils/blob/47d0be719a8243e7805e8070fcec857427529508/lib/isUrlRequest.js
13+
*/
14+
function isUrlRequest(url, root) {
15+
// An URL is not an request if
16+
17+
// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
18+
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
19+
return false;
20+
}
21+
22+
// 2. It's a protocol-relative
23+
if (/^\/\//.test(url)) {
24+
return false;
25+
}
26+
27+
// 3. It's some kind of url for a template
28+
if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.test(url)) {
29+
return false;
30+
}
31+
32+
// 4. It's also not an request if root isn't set and it's a root-relative url
33+
if ((root === undefined || root === false) && /^\//.test(url)) {
34+
return false;
35+
}
36+
37+
return true;
38+
}
39+
1040
/**
1141
* Create a value processing function for a given file path.
1242
*
@@ -117,7 +147,7 @@ function valueProcessor({ join, root, directory }) {
117147
* @return {boolean} True for relative uri
118148
*/
119149
function testIsRelative(uri) {
120-
return !!uri && loaderUtils.isUrlRequest(uri, false) && !path.isAbsolute(uri) && (uri.indexOf('~') !== 0);
150+
return !!uri && isUrlRequest(uri, false) && !path.isAbsolute(uri) && (uri.indexOf('~') !== 0);
121151
}
122152

123153
/**
@@ -128,7 +158,7 @@ function valueProcessor({ join, root, directory }) {
128158
* @return {boolean} True for absolute uri
129159
*/
130160
function testIsAbsolute(uri) {
131-
return !!uri && (typeof root === 'string') && loaderUtils.isUrlRequest(uri, root) &&
161+
return !!uri && (typeof root === 'string') && isUrlRequest(uri, root) &&
132162
(/^\//.test(uri) || path.isAbsolute(uri));
133163
}
134164
}

0 commit comments

Comments
 (0)