123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 'use strict'
- const tap = require('tap')
- const test = tap.test
- const fastifyURI = require('../')
- const urijs = require('uri-js')
- test('compatibility Parse', (t) => {
- const toParse = [
- '//www.g.com/error\n/bleh/bleh',
- 'https://fastify.org',
- '/definitions/Record%3Cstring%2CPerson%3E',
- '//10.10.10.10',
-
- '//[2001:db8::7%en0]',
- '//[2001:dbZ::1]:80',
- '//[2001:db8::1]:80',
- '//[2001:db8::001]:80',
- 'uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',
- 'http://user:pass@example.com:123/one/space in.url?q1=a1&q2=a2#body',
- '//[::ffff:129.144.52.38]',
- 'uri://10.10.10.10.example.com/en/process',
- '//[2606:2800:220:1:248:1893:25c8:1946]/test',
- 'ws://example.com/chat',
- 'ws://example.com/foo?bar=baz',
- 'wss://example.com/?bar=baz',
- 'wss://example.com/chat',
- 'wss://example.com/foo?bar=baz',
- 'wss://example.com/?bar=baz',
- 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
- 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6',
- 'urn:example:%D0%B0123,z456',
- '//[2606:2800:220:1:248:1893:25c8:1946:43209]',
- 'http://foo.bar',
- 'http://',
- '#/$defs/stringMap',
- '#/$defs/string%20Map',
- '#/$defs/string Map',
- '//?json=%7B%22foo%22%3A%22bar%22%7D'
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ]
- toParse.forEach((x) => {
- t.same(fastifyURI.parse(x), urijs.parse(x), 'Compatibility parse: ' + x)
- })
- t.end()
- })
- test('compatibility serialize', (t) => {
- const toSerialize = [
- { host: '10.10.10.10.example.com' },
- { host: '2001:db8::7' },
- { host: '::ffff:129.144.52.38' },
- { host: '2606:2800:220:1:248:1893:25c8:1946' },
- { host: '10.10.10.10.example.com' },
- { host: '10.10.10.10' },
- { path: '?query' },
- { path: 'foo:bar' },
- { path: '//path' },
- {
- scheme: 'uri',
- host: 'example.com',
- port: '9000'
- },
- {
- scheme: 'uri',
- userinfo: 'foo:bar',
- host: 'example.com',
- port: 1,
- path: 'path',
- query: 'query',
- fragment: 'fragment'
- },
- {
- scheme: '',
- userinfo: '',
- host: '',
- port: 0,
- path: '',
- query: '',
- fragment: ''
- },
- {
- scheme: undefined,
- userinfo: undefined,
- host: undefined,
- port: undefined,
- path: undefined,
- query: undefined,
- fragment: undefined
- },
- { host: 'fe80::a%en1' },
- { host: 'fe80::a%25en1' },
- {
- scheme: 'ws',
- host: 'example.com',
- resourceName: '/foo?bar',
- secure: true
- },
- {
- scheme: 'scheme',
- path: 'with:colon'
- }
- ]
- toSerialize.forEach((x) => {
- const r = JSON.stringify(x)
- t.same(
- fastifyURI.serialize(x),
- urijs.serialize(x),
- 'Compatibility serialize: ' + JSON.stringify(r)
- )
- })
- t.end()
- })
|