basant307/AI_Governance_Project
048
1'use strict'2 3const test = require('tape')4const fastURI = require('..')5 6test('URI parse', (t) => {7 let components8 9 // scheme10 components = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 = fastURI.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 // malformed percent-encoded fragment must not throw154 components = fastURI.parse('http://example.com/#%E0%A4A')155 t.equal(components.error, 'URI malformed', 'malformed fragment errors')156 t.equal(components.fragment, '%E0%A4A', 'malformed fragment is preserved')157 158 // all159 components = fastURI.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')160 t.equal(components.error, undefined, 'all errors')161 t.equal(components.scheme, 'uri', 'scheme')162 // t.equal(components.authority, "user:pass@example.com:123", "authority");163 t.equal(components.userinfo, 'user:pass', 'userinfo')164 t.equal(components.host, 'example.com', 'host')165 t.equal(components.port, 123, 'port')166 t.equal(components.path, '/one/two.three', 'path')167 t.equal(components.query, 'q1=a1&q2=a2', 'query')168 t.equal(components.fragment, 'body', 'fragment')169 170 // IPv4address171 components = fastURI.parse('//10.10.10.10')172 t.equal(components.error, undefined, 'IPv4address errors')173 t.equal(components.scheme, undefined, 'scheme')174 t.equal(components.userinfo, undefined, 'userinfo')175 t.equal(components.host, '10.10.10.10', 'host')176 t.equal(components.port, undefined, 'port')177 t.equal(components.path, '', 'path')178 t.equal(components.query, undefined, 'query')179 t.equal(components.fragment, undefined, 'fragment')180 181 // IPv4address with unformated 0 stay as-is182 components = fastURI.parse('//10.10.000.10') // not valid as per https://datatracker.ietf.org/doc/html/rfc5954#section-4.1183 t.equal(components.error, undefined, 'IPv4address errors')184 t.equal(components.scheme, undefined, 'scheme')185 t.equal(components.userinfo, undefined, 'userinfo')186 t.equal(components.host, '10.10.000.10', 'host')187 t.equal(components.port, undefined, 'port')188 t.equal(components.path, '', 'path')189 t.equal(components.query, undefined, 'query')190 t.equal(components.fragment, undefined, 'fragment')191 components = fastURI.parse('//01.01.01.01') // not valid in URIs: https://datatracker.ietf.org/doc/html/rfc3986#section-7.4192 t.equal(components.error, undefined, 'IPv4address errors')193 t.equal(components.scheme, undefined, 'scheme')194 t.equal(components.userinfo, undefined, 'userinfo')195 t.equal(components.host, '01.01.01.01', 'host')196 t.equal(components.port, undefined, 'port')197 t.equal(components.path, '', 'path')198 t.equal(components.query, undefined, 'query')199 t.equal(components.fragment, undefined, 'fragment')200 201 // IPv6address202 components = fastURI.parse('//[2001:db8::7]')203 t.equal(components.error, undefined, 'IPv4address errors')204 t.equal(components.scheme, undefined, 'scheme')205 t.equal(components.userinfo, undefined, 'userinfo')206 t.equal(components.host, '2001:db8::7', 'host')207 t.equal(components.port, undefined, 'port')208 t.equal(components.path, '', 'path')209 t.equal(components.query, undefined, 'query')210 t.equal(components.fragment, undefined, 'fragment')211 212 // invalid IPv6213 components = fastURI.parse('//[2001:dbZ::7]')214 t.equal(components.host, '[2001:dbz::7]')215 216 // mixed IPv4address & IPv6address217 components = fastURI.parse('//[::ffff:129.144.52.38]')218 t.equal(components.error, undefined, 'IPv4address errors')219 t.equal(components.scheme, undefined, 'scheme')220 t.equal(components.userinfo, undefined, 'userinfo')221 t.equal(components.host, '::ffff:129.144.52.38', 'host')222 t.equal(components.port, undefined, 'port')223 t.equal(components.path, '', 'path')224 t.equal(components.query, undefined, 'query')225 t.equal(components.fragment, undefined, 'fragment')226 227 // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)228 components = fastURI.parse('uri://10.10.10.10.example.com/en/process')229 t.equal(components.error, undefined, 'mixed errors')230 t.equal(components.scheme, 'uri', 'scheme')231 t.equal(components.userinfo, undefined, 'userinfo')232 t.equal(components.host, '10.10.10.10.example.com', 'host')233 t.equal(components.port, undefined, 'port')234 t.equal(components.path, '/en/process', 'path')235 t.equal(components.query, undefined, 'query')236 t.equal(components.fragment, undefined, 'fragment')237 238 // IPv6address, example from bkw (https://github.com/garycourt/uri-js/pull/16)239 components = fastURI.parse('//[2606:2800:220:1:248:1893:25c8:1946]/test')240 t.equal(components.error, undefined, 'IPv6address errors')241 t.equal(components.scheme, undefined, 'scheme')242 t.equal(components.userinfo, undefined, 'userinfo')243 t.equal(components.host, '2606:2800:220:1:248:1893:25c8:1946', 'host')244 t.equal(components.port, undefined, 'port')245 t.equal(components.path, '/test', 'path')246 t.equal(components.query, undefined, 'query')247 t.equal(components.fragment, undefined, 'fragment')248 249 // IPv6address, example from RFC 5952250 components = fastURI.parse('//[2001:db8::1]:80')251 t.equal(components.error, undefined, 'IPv6address errors')252 t.equal(components.scheme, undefined, 'scheme')253 t.equal(components.userinfo, undefined, 'userinfo')254 t.equal(components.host, '2001:db8::1', 'host')255 t.equal(components.port, 80, 'port')256 t.equal(components.path, '', 'path')257 t.equal(components.query, undefined, 'query')258 t.equal(components.fragment, undefined, 'fragment')259 260 // IPv6address with zone identifier, RFC 6874261 components = fastURI.parse('//[fe80::a%25en1]')262 t.equal(components.error, undefined, 'IPv4address errors')263 t.equal(components.scheme, undefined, 'scheme')264 t.equal(components.userinfo, undefined, 'userinfo')265 t.equal(components.host, 'fe80::a%en1', 'host')266 t.equal(components.port, undefined, 'port')267 t.equal(components.path, '', 'path')268 t.equal(components.query, undefined, 'query')269 t.equal(components.fragment, undefined, 'fragment')270 271 // IPv6address with an unescaped interface specifier, example from pekkanikander (https://github.com/garycourt/uri-js/pull/22)272 components = fastURI.parse('//[2001:db8::7%en0]')273 t.equal(components.error, undefined, 'IPv6address interface errors')274 t.equal(components.scheme, undefined, 'scheme')275 t.equal(components.userinfo, undefined, 'userinfo')276 t.equal(components.host, '2001:db8::7%en0', 'host')277 t.equal(components.port, undefined, 'port')278 t.equal(components.path, '', 'path')279 t.equal(components.query, undefined, 'query')280 t.equal(components.fragment, undefined, 'fragment')281 282 // UUID V1283 components = fastURI.parse('urn:uuid:b571b0bc-4713-11ec-81d3-0242ac130003')284 t.equal(components.error, undefined, 'errors')285 t.equal(components.scheme, 'urn', 'scheme')286 // t.equal(components.authority, undefined, "authority");287 t.equal(components.userinfo, undefined, 'userinfo')288 t.equal(components.host, undefined, 'host')289 t.equal(components.port, undefined, 'port')290 t.equal(components.path, undefined, 'path')291 t.equal(components.query, undefined, 'query')292 t.equal(components.fragment, undefined, 'fragment')293 t.equal(components.nid, 'uuid', 'nid')294 t.equal(components.nss, undefined, 'nss')295 t.equal(components.uuid, 'b571b0bc-4713-11ec-81d3-0242ac130003', 'uuid')296 297 // UUID v4298 components = fastURI.parse('urn:uuid:97a32222-89b7-420e-8507-4360723e2c2a')299 t.equal(components.uuid, '97a32222-89b7-420e-8507-4360723e2c2a', 'uuid')300 301 components = fastURI.parse('urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')302 t.notSame(components.error, undefined, 'errors')303 304 components = fastURI.parse('urn:foo:a123,456')305 t.equal(components.error, undefined, 'errors')306 t.equal(components.scheme, 'urn', 'scheme')307 // t.equal(components.authority, undefined, "authority");308 t.equal(components.userinfo, undefined, 'userinfo')309 t.equal(components.host, undefined, 'host')310 t.equal(components.port, undefined, 'port')311 t.equal(components.path, undefined, 'path')312 t.equal(components.query, undefined, 'query')313 t.equal(components.fragment, undefined, 'fragment')314 t.equal(components.nid, 'foo', 'nid')315 t.equal(components.nss, 'a123,456', 'nss')316 317 components = fastURI.parse('//[2606:2800:220:1:248:1893:25c8:1946:43209]')318 t.equal(components.host, '[2606:2800:220:1:248:1893:25c8:1946:43209]')319 320 components = fastURI.parse('urn:foo:|\\24fpl')321 t.equal(components.error, 'URN can not be parsed.')322 t.end()323})324 