Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
709 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | const path = require('path');
|
---|
4 |
|
---|
5 | function isUrlRequest(url, root) {
|
---|
6 | // An URL is not an request if
|
---|
7 |
|
---|
8 | // 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
|
---|
9 | if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
|
---|
10 | return false;
|
---|
11 | }
|
---|
12 |
|
---|
13 | // 2. It's a protocol-relative
|
---|
14 | if (/^\/\//.test(url)) {
|
---|
15 | return false;
|
---|
16 | }
|
---|
17 |
|
---|
18 | // 3. It's some kind of url for a template
|
---|
19 | if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.test(url)) {
|
---|
20 | return false;
|
---|
21 | }
|
---|
22 |
|
---|
23 | // 4. It's also not an request if root isn't set and it's a root-relative url
|
---|
24 | if ((root === undefined || root === false) && /^\//.test(url)) {
|
---|
25 | return false;
|
---|
26 | }
|
---|
27 |
|
---|
28 | return true;
|
---|
29 | }
|
---|
30 |
|
---|
31 | module.exports = isUrlRequest;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.