WXL
3 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict'
 
const test = require('tape')
const fastURI = require('..')
 
test('RFC 3986', (t) => {
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
 
  // A.  If the input buffer begins with a prefix of "../" or "./",
  //     then remove that prefix from the input buffer; otherwise,
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './', secure: true }),
    'http://example.com/', 'http://example.com/')
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../../', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '././', secure: true }),
    'http://example.com/', 'http://example.com/')
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './../', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.././', secure: true }),
    'http://example.com/', 'http://example.com/')
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../../foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '././foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './../foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.././foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
 
  // B.  if the input buffer begins with a prefix of "/./" or "/.",
  //     where "." is a complete path segment, then replace that
  //     prefix with "/" in the input buffer; otherwise,
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/./', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/./foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.././foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
 
  // C.  if the input buffer begins with a prefix of "/../" or "/..",
  //     where ".." is a complete path segment, then replace that
  //     prefix with "/" in the input buffer and remove the last
  //     segment and its preceding "/" (if any) from the output
  //     buffer; otherwise,
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/../', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/..', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/../foo', secure: true }),
    'http://example.com/foo', 'http://example.com/foo')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/..', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/bar/..', secure: true }),
    'http://example.com/foo/', 'http://example.com/foo/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/../bar/..', secure: true }),
    'http://example.com/', 'http://example.com/')
 
  // D.  if the input buffer consists only of "." or "..", then remove
  //     that from the input buffer; otherwise,
 
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/..', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.', secure: true }),
    'http://example.com/', 'http://example.com/')
  t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '..', secure: true }),
    'http://example.com/', 'http://example.com/')
 
  t.end()
})