Skip to content

Commit 47e2e02

Browse files
authoredDec 21, 2018
fix: ignore all nonstandard extension protocols
2 parents 822f518 + dd9326b commit 47e2e02

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
 

‎lib/isUrlRequest.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ function isUrlRequest(url, root) {
55
// 1. it's a Data Url
66
// 2. it's an absolute url or and protocol-relative
77
// 3. it's some kind of url for a template
8-
if(/^data:|^chrome-extension:|^moz-extension:|^ms-browser-extension:|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(url)) return false;
8+
if(/^data:|^.+-extension:\/|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(url)) {
9+
return false;
10+
}
11+
912
// 4. It's also not an request if root isn't set and it's a root-relative url
10-
if((root === undefined || root === false) && /^\//.test(url)) return false;
13+
if((root === undefined || root === false) && /^\//.test(url)) {
14+
return false;
15+
}
16+
1117
return true;
1218
}
1319

‎test/isUrlRequest.test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,37 @@ describe("isUrlRequest()", () => {
1616
[["//google.com"], false, "should be negative for scheme-agnostic urls"],
1717
[["http://google.com"], false, "should be negative for http urls"],
1818
[["https://google.com"], false, "should be negative for https urls"],
19-
[["chrome-extension://"], false, "should be negative for https urls"],
20-
[["moz-extension://"], false, "should be negative for https urls"],
21-
[["ms-browser-extension://"], false, "should be negative for https urls"],
19+
20+
[["chrome-extension://"], false, "should be negative for nonstandard urls"],
21+
[["moz-extension://"], false, "should be negative for nonstandard urls"],
22+
[["ms-browser-extension://"], false, "should be negative for nonstandard urls"],
23+
[["custom-extension://"], false, "should be negative for nonstandard urls"],
24+
2225
[["path/to/thing"], true, "should be positive for implicit relative urls"],
2326
[["./path/to/thing"], true, "should be positive for explicit relative urls"],
2427
[["~path/to/thing"], true, "should be positive for module urls (with ~)"],
2528
[["some/other/stuff/and/then~path/to/thing"], true, "should be positive for module urls with path prefix"],
2629
[["./some/other/stuff/and/then~path/to/thing"], true, "should be positive for module urls with relative path prefix"],
30+
2731
// with root (normal path)
2832
[["path/to/thing", "root/dir"], true, "should be positive with root if implicit relative url"],
2933
[["./path/to/thing", "root/dir"], true, "should be positive with root if explicit relative url"],
3034
[["/path/to/thing", "root/dir"], true, "should be positive with root if root-relative url"],
35+
3136
// with root (boolean)
3237
[["/path/to/thing", true], true, "should be positive for root-relative if root = `true`"],
38+
3339
// with root (boolean) on Windows
3440
[["C:\\path\\to\\thing"], true, "should be positive for Windows absolute paths with drive letter"],
3541
[["\\\\?\\UNC\\ComputerName\\path\\to\\thing"], true, "should be positive for Windows absolute UNC paths"],
42+
3643
// with root (module)
3744
[["/path/to/thing", "~"], true, "should be positive for module url if root = ~"],
45+
3846
// with root (module path)
3947
[["/path/to/thing", "~module"], true, "should be positive for module prefixes when root starts with ~"],
4048
[["/path/to/thing", "~module/"], true, "should be positive for module prefixes (with trailing slash) when root starts with ~"],
49+
4150
// error cases
4251
[["/path/to/thing", 1], new ExpectedError(/unexpected parameters/i), "should throw an error on invalid root"],
4352

0 commit comments

Comments
 (0)
Please sign in to comment.