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