strong-tie/inbound-calls
0
1'use strict'2 3const test = require('tape')4const URI = require('../')5 6test('URI parse', (t) => {7 let components8 9 // scheme10 components = URI.parse('uri:')11 t.equal(components.error, undefined, 'scheme errors')12 t.equal(components.scheme, 'uri', 'scheme')13 // t.equal(components.authority, undefined, "authority");14 t.equal(components.userinfo, undefined, 'userinfo')15 t.equal(components.host, undefined, 'host')16 t.equal(components.port, undefined, 'port')17 t.equal(components.path, '', 'path')18 t.equal(components.query, undefined, 'query')19 t.equal(components.fragment, undefined, 'fragment')20 21 // userinfo22 components = URI.parse('//@')23 t.equal(components.error, undefined, 'userinfo errors')24 t.equal(components.scheme, undefined, 'scheme')25 // t.equal(components.authority, "@", "authority");26 t.equal(components.userinfo, '', 'userinfo')27 t.equal(components.host, '', 'host')28 t.equal(components.port, undefined, 'port')29 t.equal(components.path, '', 'path')30 t.equal(components.query, undefined, 'query')31 t.equal(components.fragment, undefined, 'fragment')32 33 // host34 components = URI.parse('//')35 t.equal(components.error, undefined, 'host errors')36 t.equal(components.scheme, undefined, 'scheme')37 // t.equal(components.authority, "", "authority");38 t.equal(components.userinfo, undefined, 'userinfo')39 t.equal(components.host, '', 'host')40 t.equal(components.port, undefined, 'port')41 t.equal(components.path, '', 'path')42 t.equal(components.query, undefined, 'query')43 t.equal(components.fragment, undefined, 'fragment')44 45 // port46 components = URI.parse('//:')47 t.equal(components.error, undefined, 'port errors')48 t.equal(components.scheme, undefined, 'scheme')49 // t.equal(components.authority, ":", "authority");50 t.equal(components.userinfo, undefined, 'userinfo')51 t.equal(components.host, '', 'host')52 t.equal(components.port, '', 'port')53 t.equal(components.path, '', 'path')54 t.equal(components.query, undefined, 'query')55 t.equal(components.fragment, undefined, 'fragment')56 57 // path58 components = URI.parse('')59 t.equal(components.error, undefined, 'path errors')60 t.equal(components.scheme, undefined, 'scheme')61 // t.equal(components.authority, undefined, "authority");62 t.equal(components.userinfo, undefined, 'userinfo')63 t.equal(components.host, undefined, 'host')64 t.equal(components.port, undefined, 'port')65 t.equal(components.path, '', 'path')66 t.equal(components.query, undefined, 'query')67 t.equal(components.fragment, undefined, 'fragment')68 69 // query70 components = URI.parse('?')71 t.equal(components.error, undefined, 'query errors')72 t.equal(components.scheme, undefined, 'scheme')73 // t.equal(components.authority, undefined, "authority");74 t.equal(components.userinfo, undefined, 'userinfo')75 t.equal(components.host, undefined, 'host')76 t.equal(components.port, undefined, 'port')77 t.equal(components.path, '', 'path')78 t.equal(components.query, '', 'query')79 t.equal(components.fragment, undefined, 'fragment')80 81 // fragment82 components = URI.parse('#')83 t.equal(components.error, undefined, 'fragment errors')84 t.equal(components.scheme, undefined, 'scheme')85 // t.equal(components.authority, undefined, "authority");86 t.equal(components.userinfo, undefined, 'userinfo')87 t.equal(components.host, undefined, 'host')88 t.equal(components.port, undefined, 'port')89 t.equal(components.path, '', 'path')90 t.equal(components.query, undefined, 'query')91 t.equal(components.fragment, '', 'fragment')92 93 // fragment with character tabulation94 components = URI.parse('#\t')95 t.equal(components.error, undefined, 'path errors')96 t.equal(components.scheme, undefined, 'scheme')97 // t.equal(components.authority, undefined, "authority");98 t.equal(components.userinfo, undefined, 'userinfo')99 t.equal(components.host, undefined, 'host')100 t.equal(components.port, undefined, 'port')101 t.equal(components.path, '', 'path')102 t.equal(components.query, undefined, 'query')103 t.equal(components.fragment, '%09', 'fragment')104 105 // fragment with line feed106 components = URI.parse('#\n')107 t.equal(components.error, undefined, 'path errors')108 t.equal(components.scheme, undefined, 'scheme')109 // t.equal(components.authority, undefined, "authority");110 t.equal(components.userinfo, undefined, 'userinfo')111 t.equal(components.host, undefined, 'host')112 t.equal(components.port, undefined, 'port')113 t.equal(components.path, '', 'path')114 t.equal(components.query, undefined, 'query')115 t.equal(components.fragment, '%0A', 'fragment')116 117 // fragment with line tabulation118 components = URI.parse('#\v')119 t.equal(components.error, undefined, 'path errors')120 t.equal(components.scheme, undefined, 'scheme')121 // t.equal(components.authority, undefined, "authority");122 t.equal(components.userinfo, undefined, 'userinfo')123 t.equal(components.host, undefined, 'host')124 t.equal(components.port, undefined, 'port')125 t.equal(components.path, '', 'path')126 t.equal(components.query, undefined, 'query')127 t.equal(components.fragment, '%0B', 'fragment')128 129 // fragment with form feed130 components = URI.parse('#\f')131 t.equal(components.error, undefined, 'path errors')132 t.equal(components.scheme, undefined, 'scheme')133 // t.equal(components.authority, undefined, "authority");134 t.equal(components.userinfo, undefined, 'userinfo')135 t.equal(components.host, undefined, 'host')136 t.equal(components.port, undefined, 'port')137 t.equal(components.path, '', 'path')138 t.equal(components.query, undefined, 'query')139 t.equal(components.fragment, '%0C', 'fragment')140 141 // fragment with carriage return142 components = URI.parse('#\r')143 t.equal(components.error, undefined, 'path errors')144 t.equal(components.scheme, undefined, 'scheme')145 // t.equal(components.authority, undefined, "authority");146 t.equal(components.userinfo, undefined, 'userinfo')147 t.equal(components.host, undefined, 'host')148 t.equal(components.port, undefined, 'port')149 t.equal(components.path, '', 'path')150 t.equal(components.query, undefined, 'query')151 t.equal(components.fragment, '%0D', 'fragment')152 153 // all154 components = URI.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')155 t.equal(components.error, undefined, 'all errors')156 t.equal(components.scheme, 'uri', 'scheme')157 // t.equal(components.authority, "user:pass@example.com:123", "authority");158 t.equal(components.userinfo, 'user:pass', 'userinfo')159 t.equal(components.host, 'example.com', 'host')160 t.equal(components.port, 123, 'port')161 t.equal(components.path, '/one/two.three', 'path')162 t.equal(components.query, 'q1=a1&q2=a2', 'query')163 t.equal(components.fragment, 'body', 'fragment')164 165 // IPv4address166 components = URI.parse('//10.10.10.10')167 t.equal(components.error, undefined, 'IPv4address errors')168 t.equal(components.scheme, undefined, 'scheme')169 t.equal(components.userinfo, undefined, 'userinfo')170 t.equal(components.host, '10.10.10.10', 'host')171 t.equal(components.port, undefined, 'port')172 t.equal(components.path, '', 'path')173 t.equal(components.query, undefined, 'query')174 t.equal(components.fragment, undefined, 'fragment')175 176 // IPv4address with unformated 0 stay as-is177 components = URI.parse('//10.10.000.10') // not valid as per https://datatracker.ietf.org/doc/html/rfc5954#section-4.1178 t.equal(components.error, undefined, 'IPv4address errors')179 t.equal(components.scheme, undefined, 'scheme')180 t.equal(components.userinfo, undefined, 'userinfo')181 t.equal(components.host, '10.10.000.10', 'host')182 t.equal(components.port, undefined, 'port')183 t.equal(components.path, '', 'path')184 t.equal(components.query, undefined, 'query')185 t.equal(components.fragment, undefined, 'fragment')186 components = URI.parse('//01.01.01.01') // not valid in URIs: https://datatracker.ietf.org/doc/html/rfc3986#section-7.4187 t.equal(components.error, undefined, 'IPv4address errors')188 t.equal(components.scheme, undefined, 'scheme')189 t.equal(components.userinfo, undefined, 'userinfo')190 t.equal(components.host, '01.01.01.01', 'host')191 t.equal(components.port, undefined, 'port')192 t.equal(components.path, '', 'path')193 t.equal(components.query, undefined, 'query')194 t.equal(components.fragment, undefined, 'fragment')195 196 // IPv6address197 components = URI.parse('//[2001:db8::7]')198 t.equal(components.error, undefined, 'IPv4address errors')199 t.equal(components.scheme, undefined, 'scheme')200 t.equal(components.userinfo, undefined, 'userinfo')201 t.equal(components.host, '2001:db8::7', 'host')202 t.equal(components.port, undefined, 'port')203 t.equal(components.path, '', 'path')204 t.equal(components.query, undefined, 'query')205 t.equal(components.fragment, undefined, 'fragment')206 207 // invalid IPv6208 components = URI.parse('//[2001:dbZ::7]')209 t.equal(components.host, '[2001:dbz::7]')210 211 // mixed IPv4address & IPv6address212 components = URI.parse('//[::ffff:129.144.52.38]')213 t.equal(components.error, undefined, 'IPv4address errors')214 t.equal(components.scheme, undefined, 'scheme')215 t.equal(components.userinfo, undefined, 'userinfo')216 t.equal(components.host, '::ffff:129.144.52.38', 'host')217 t.equal(components.port, undefined, 'port')218 t.equal(components.path, '', 'path')219 t.equal(components.query, undefined, 'query')220 t.equal(components.fragment, undefined, 'fragment')221 222 // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)223 components = URI.parse('uri://10.10.10.10.example.com/en/process')224 t.equal(components.error, undefined, 'mixed errors')225 t.equal(components.scheme, 'uri', 'scheme')226 t.equal(components.userinfo, undefined, 'userinfo')227 t.equal(components.host, '10.10.10.10.example.com', 'host')228 t.equal(components.port, undefined, 'port')229 t.equal(components.path, '/en/process', 'path')230 t.equal(components.query, undefined, 'query')231 t.equal(components.fragment, undefined, 'fragment')232 233 // IPv6address, example from bkw (https://github.com/garycourt/uri-js/pull/16)234 components = URI.parse('//[2606:2800:220:1:248:1893:25c8:1946]/test')235 t.equal(components.error, undefined, 'IPv6address errors')236 t.equal(components.scheme, undefined, 'scheme')237 t.equal(components.userinfo, undefined, 'userinfo')238 t.equal(components.host, '2606:2800:220:1:248:1893:25c8:1946', 'host')239 t.equal(components.port, undefined, 'port')240 t.equal(components.path, '/test', 'path')241 t.equal(components.query, undefined, 'query')242 t.equal(components.fragment, undefined, 'fragment')243 244 // IPv6address, example from RFC 5952245 components = URI.parse('//[2001:db8::1]:80')246 t.equal(components.error, undefined, 'IPv6address errors')247 t.equal(components.scheme, undefined, 'scheme')248 t.equal(components.userinfo, undefined, 'userinfo')249 t.equal(components.host, '2001:db8::1', 'host')250 t.equal(components.port, 80, 'port')251 t.equal(components.path, '', 'path')252 t.equal(components.query, undefined, 'query')253 t.equal(components.fragment, undefined, 'fragment')254 255 // IPv6address with zone identifier, RFC 6874256 components = URI.parse('//[fe80::a%25en1]')257 t.equal(components.error, undefined, 'IPv4address errors')258 t.equal(components.scheme, undefined, 'scheme')259 t.equal(components.userinfo, undefined, 'userinfo')260 t.equal(components.host, 'fe80::a%en1', 'host')261 t.equal(components.port, undefined, 'port')262 t.equal(components.path, '', 'path')263 t.equal(components.query, undefined, 'query')264 t.equal(components.fragment, undefined, 'fragment')265 266 // IPv6address with an unescaped interface specifier, example from pekkanikander (https://github.com/garycourt/uri-js/pull/22)267 components = URI.parse('//[2001:db8::7%en0]')268 t.equal(components.error, undefined, 'IPv6address interface errors')269 t.equal(components.scheme, undefined, 'scheme')270 t.equal(components.userinfo, undefined, 'userinfo')271 t.equal(components.host, '2001:db8::7%en0', 'host')272 t.equal(components.port, undefined, 'port')273 t.equal(components.path, '', 'path')274 t.equal(components.query, undefined, 'query')275 t.equal(components.fragment, undefined, 'fragment')276 277 // UUID V1278 components = URI.parse('urn:uuid:b571b0bc-4713-11ec-81d3-0242ac130003')279 t.equal(components.error, undefined, 'errors')280 t.equal(components.scheme, 'urn', 'scheme')281 // t.equal(components.authority, undefined, "authority");282 t.equal(components.userinfo, undefined, 'userinfo')283 t.equal(components.host, undefined, 'host')284 t.equal(components.port, undefined, 'port')285 t.equal(components.path, undefined, 'path')286 t.equal(components.query, undefined, 'query')287 t.equal(components.fragment, undefined, 'fragment')288 t.equal(components.nid, 'uuid', 'nid')289 t.equal(components.nss, undefined, 'nss')290 t.equal(components.uuid, 'b571b0bc-4713-11ec-81d3-0242ac130003', 'uuid')291 292 // UUID v4293 components = URI.parse('urn:uuid:97a32222-89b7-420e-8507-4360723e2c2a')294 t.equal(components.uuid, '97a32222-89b7-420e-8507-4360723e2c2a', 'uuid')295 296 components = URI.parse('urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')297 t.notSame(components.error, undefined, 'errors')298 299 components = URI.parse('urn:foo:a123,456')300 t.equal(components.error, undefined, 'errors')301 t.equal(components.scheme, 'urn', 'scheme')302 // t.equal(components.authority, undefined, "authority");303 t.equal(components.userinfo, undefined, 'userinfo')304 t.equal(components.host, undefined, 'host')305 t.equal(components.port, undefined, 'port')306 t.equal(components.path, undefined, 'path')307 t.equal(components.query, undefined, 'query')308 t.equal(components.fragment, undefined, 'fragment')309 t.equal(components.nid, 'foo', 'nid')310 t.equal(components.nss, 'a123,456', 'nss')311 312 components = URI.parse('//[2606:2800:220:1:248:1893:25c8:1946:43209]')313 t.equal(components.host, '[2606:2800:220:1:248:1893:25c8:1946:43209]')314 315 components = URI.parse('urn:foo:|\\24fpl')316 t.equal(components.error, 'URN can not be parsed.')317 t.end()318})319 