Projekt

Obecné

Profil

Stáhnout (709 Bajtů) Statistiky
| Větev: | Revize:
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;
(7-7/11)