fast-uri 4.1.5 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/SECURITY.md +62 -13
- package/index.js +30 -3
- package/lib/utils.js +54 -10
- package/package.json +1 -1
- package/test/fixtures/uri-js-parse.json +1 -0
- package/test/ipv6-validation.test.js +130 -0
- package/types/index.d.ts +16 -0
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ fast-uri supports inserting custom [scheme](https://en.wikipedia.org/wiki/URI_sc
|
|
|
99
99
|
* wss \[[RFC 6455](https://www.ietf.org/rfc/rfc6455.txt)\]
|
|
100
100
|
* urn \[[RFC 2141](https://www.ietf.org/rfc/rfc2141.txt)\]
|
|
101
101
|
* urn:uuid \[[RFC 4122](https://www.ietf.org/rfc/rfc4122.txt)\]
|
|
102
|
+
* mailto \[[RFC 6068](https://www.rfc-editor.org/rfc/rfc6068)\]
|
|
102
103
|
|
|
103
104
|
|
|
104
105
|
## Benchmarks
|
package/SECURITY.md
CHANGED
|
@@ -15,38 +15,87 @@ Reports based solely on comparing or mixing parsers that follow these different
|
|
|
15
15
|
standards are out of scope. Applications must use the same parsing and
|
|
16
16
|
normalization rules for both security decisions and subsequent URI use.
|
|
17
17
|
|
|
18
|
+
A WHATWG comparison may be useful supporting evidence, but a parser difference
|
|
19
|
+
is not by itself a vulnerability. A report remains in scope when it independently
|
|
20
|
+
demonstrates a defect in `fast-uri`'s RFC or documented behavior for a supported
|
|
21
|
+
scheme and a concrete security impact when the application uses `fast-uri`
|
|
22
|
+
consistently. An exploit that requires validating with `fast-uri` and then
|
|
23
|
+
passing the original, unmodified input to a parser with different rules is an
|
|
24
|
+
application parser-confusion issue.
|
|
25
|
+
|
|
18
26
|
Reports are assessed based on reproducibility, documented supported usage, and
|
|
19
27
|
concrete security impact—not merely on whether they mention WHATWG URL
|
|
20
|
-
behavior.
|
|
21
|
-
scheme remain eligible for evaluation.
|
|
28
|
+
behavior.
|
|
22
29
|
|
|
23
30
|
## Threat model
|
|
24
31
|
|
|
25
32
|
`fast-uri`'s threat model extends the
|
|
26
33
|
[Node.js threat model](https://github.com/nodejs/node/blob/main/SECURITY.md#the-nodejs-threat-model).
|
|
27
34
|
|
|
28
|
-
**Trusted:** Application code,
|
|
29
|
-
|
|
35
|
+
**Trusted:** Application code, structured component objects constructed or
|
|
36
|
+
modified by application code and passed directly to `serialize()`, parser
|
|
37
|
+
options, configuration, and the runtime environment.
|
|
30
38
|
|
|
31
39
|
**Untrusted:** URI and IRI strings passed to the package's public APIs.
|
|
32
40
|
|
|
41
|
+
## Vulnerability classification
|
|
42
|
+
|
|
43
|
+
A report is treated as a vulnerability when it demonstrates all of the
|
|
44
|
+
following:
|
|
45
|
+
|
|
46
|
+
1. Attacker-controlled input reaches a public API through documented,
|
|
47
|
+
supported usage.
|
|
48
|
+
2. `fast-uri` violates an applicable RFC or its documented API contract.
|
|
49
|
+
3. The defect creates a concrete confidentiality, integrity, or availability
|
|
50
|
+
impact in a realistic supported use case.
|
|
51
|
+
4. The impact does not depend solely on application misuse, an unsupported
|
|
52
|
+
scheme, a different parser interpreting the original input, or another
|
|
53
|
+
package's behavior.
|
|
54
|
+
|
|
55
|
+
A reproducible bug can still merit a normal issue and fix without meeting the
|
|
56
|
+
security-vulnerability threshold.
|
|
57
|
+
|
|
33
58
|
### Examples of vulnerabilities
|
|
34
59
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
|
|
60
|
+
- `parse()`, `normalize()`, or `resolve()` changes an attacker-controlled
|
|
61
|
+
authority within `fast-uri`, and the report demonstrates a host security
|
|
62
|
+
control being bypassed using that output
|
|
63
|
+
- `equal()` aliases distinct URIs under the rules of a supported scheme, and
|
|
64
|
+
the report demonstrates an authorization, signature, or cache boundary being
|
|
65
|
+
bypassed
|
|
66
|
+
- One public API call on a reasonably sized malformed URI causes
|
|
67
|
+
disproportionate CPU or memory consumption, with reproducible availability
|
|
68
|
+
impact
|
|
69
|
+
- Parsing or normalization turns component data into a structural delimiter
|
|
70
|
+
and the report demonstrates a security-control bypass in documented usage
|
|
71
|
+
|
|
72
|
+
### Denial-of-service reports
|
|
73
|
+
|
|
74
|
+
A synchronous exception, parse error, or non-idempotent result is not by itself
|
|
75
|
+
a denial-of-service vulnerability. A report must demonstrate disproportionate
|
|
76
|
+
resource consumption in a public API call, or loss of availability in a
|
|
77
|
+
supported deployment despite normal exception handling. An application that
|
|
78
|
+
terminates on an uncaught exception, or repeatedly normalizes until reaching a
|
|
79
|
+
fixpoint, does not establish a package vulnerability by itself.
|
|
38
80
|
|
|
39
81
|
### Examples of non-vulnerabilities
|
|
40
82
|
|
|
41
83
|
The following are **not** considered vulnerabilities in `fast-uri`:
|
|
42
84
|
|
|
43
|
-
- **Different URL standards:**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- **Unsupported scheme semantics:**
|
|
47
|
-
`fast-uri` does not document as supported
|
|
85
|
+
- **Different URL standards:** `fast-uri` returns one host, but an application
|
|
86
|
+
passes the original input to WHATWG `URL`, `fetch`, or another parser that
|
|
87
|
+
applies different recovery, whitespace, or legacy-IP rules
|
|
88
|
+
- **Unsupported scheme semantics:** Behavior specific to schemes such as
|
|
89
|
+
`ftp` or `file`, which `fast-uri` does not document as supported
|
|
90
|
+
- **Correctness without security impact:** Non-idempotent normalization,
|
|
91
|
+
surprising equality, truncation, re-encoding, or malformed-input handling
|
|
92
|
+
without a demonstrated security boundary or availability impact
|
|
93
|
+
- **Caller-created resource use:** An application repeatedly parses or
|
|
94
|
+
normalizes a value, or fails to catch a synchronous exception
|
|
95
|
+
- **Trusted structured input:** Boundary characters supplied in a component
|
|
96
|
+
object that application code constructs and passes to `serialize()`
|
|
48
97
|
- **Application code vulnerabilities:** Security flaws in code that consumes
|
|
49
|
-
`fast-uri` output
|
|
98
|
+
`fast-uri` output contrary to its documented contract
|
|
50
99
|
- **Configuration mistakes:** Security issues caused by incorrect parser
|
|
51
100
|
options or application configuration
|
|
52
101
|
- **Missing security features:** Application-level protections that are not
|
package/index.js
CHANGED
|
@@ -89,6 +89,22 @@ function resolve (baseURI, relativeURI, options) {
|
|
|
89
89
|
return serialize(resolved, schemelessOptions)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Copies a host component together with its parse-time zone identifier (if
|
|
94
|
+
* any), so downstream recomposition does not re-derive an IPv6 zone from the
|
|
95
|
+
* ambiguous single-"%" component form. The zone is validated on use by
|
|
96
|
+
* `recomposeAuthority` rather than blindly trusted.
|
|
97
|
+
*
|
|
98
|
+
* @param {import('./types/index').URIComponent} target
|
|
99
|
+
* @param {import('./types/index').URIComponent} source
|
|
100
|
+
*/
|
|
101
|
+
function copyHost (target, source) {
|
|
102
|
+
target.host = source.host
|
|
103
|
+
if (source.ipv6Zone !== undefined) {
|
|
104
|
+
target.ipv6Zone = source.ipv6Zone
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
92
108
|
/**
|
|
93
109
|
* @param {import ('./types/index').URIComponent} base
|
|
94
110
|
* @param {import ('./types/index').URIComponent} relative
|
|
@@ -109,7 +125,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
|
|
|
109
125
|
target.scheme = relative.scheme
|
|
110
126
|
// target.authority = relative.authority;
|
|
111
127
|
target.userinfo = relative.userinfo
|
|
112
|
-
target
|
|
128
|
+
copyHost(target, relative)
|
|
113
129
|
target.port = relative.port
|
|
114
130
|
target.path = removeDotSegments(relative.path || '')
|
|
115
131
|
target.query = relative.query
|
|
@@ -117,7 +133,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
|
|
|
117
133
|
if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
|
|
118
134
|
// target.authority = relative.authority;
|
|
119
135
|
target.userinfo = relative.userinfo
|
|
120
|
-
target
|
|
136
|
+
copyHost(target, relative)
|
|
121
137
|
target.port = relative.port
|
|
122
138
|
target.path = removeDotSegments(relative.path || '')
|
|
123
139
|
target.query = relative.query
|
|
@@ -146,7 +162,7 @@ function resolveComponent (base, relative, options, skipNormalization) {
|
|
|
146
162
|
}
|
|
147
163
|
// target.authority = base.authority;
|
|
148
164
|
target.userinfo = base.userinfo
|
|
149
|
-
target
|
|
165
|
+
copyHost(target, base)
|
|
150
166
|
target.port = base.port
|
|
151
167
|
}
|
|
152
168
|
target.scheme = base.scheme
|
|
@@ -178,6 +194,7 @@ function equal (uriA, uriB, options) {
|
|
|
178
194
|
function serialize (cmpts, opts) {
|
|
179
195
|
const component = {
|
|
180
196
|
host: cmpts.host,
|
|
197
|
+
ipv6Zone: cmpts.ipv6Zone,
|
|
181
198
|
scheme: cmpts.scheme,
|
|
182
199
|
userinfo: cmpts.userinfo,
|
|
183
200
|
port: cmpts.port,
|
|
@@ -506,6 +523,16 @@ function parseWithStatus (uri, opts) {
|
|
|
506
523
|
malformedIPLiteral = hasIPLiteralBracket && (!bracketedIPLiteral || ipv6result.error === true)
|
|
507
524
|
parsed.host = isIP ? ipv6result.host : ipv6result.host.toLowerCase()
|
|
508
525
|
|
|
526
|
+
if (isIP && ipv6result.isIPV6 === true && parsed.host.indexOf('%') !== -1) {
|
|
527
|
+
// Persist the zone identifier so recomposition never has to re-derive
|
|
528
|
+
// it from the ambiguous single-"%" component form, which misreads a
|
|
529
|
+
// zone that begins with "25" as a %25 separator. It is validated on
|
|
530
|
+
// use during recomposition, so a host reassigned after parse or an
|
|
531
|
+
// input zone that does not describe the host is ignored. Only zoned
|
|
532
|
+
// literals are ambiguous; plain IPv6 addresses round-trip without it.
|
|
533
|
+
parsed.ipv6Zone = parsed.host.slice(parsed.host.indexOf('%') + 1)
|
|
534
|
+
}
|
|
535
|
+
|
|
509
536
|
if (malformedIPLiteral) {
|
|
510
537
|
parsed.error = parsed.error || 'URI host is malformed.'
|
|
511
538
|
malformedAuthorityOrPort = true
|
package/lib/utils.js
CHANGED
|
@@ -740,6 +740,37 @@ function escapePreservingEscapes (input) {
|
|
|
740
740
|
return output
|
|
741
741
|
}
|
|
742
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Rebuilds the bracketed form of a zoned IPv6 authority from the current
|
|
745
|
+
* `component.host` and its zone identifier (`component.ipv6Zone`), but only
|
|
746
|
+
* when they are consistent and describe a real zoned IPv6 literal that
|
|
747
|
+
* normalizes back to `component.host`. This validates the zone on use, so a
|
|
748
|
+
* caller-supplied `ipv6Zone` that does not match the host (or a host
|
|
749
|
+
* reassigned after `parse`) is never trusted and recomposition falls back to
|
|
750
|
+
* the normal path.
|
|
751
|
+
*
|
|
752
|
+
* @param {import('../types/index').URIComponent} component
|
|
753
|
+
* @returns {string|undefined}
|
|
754
|
+
*/
|
|
755
|
+
function recomposeZonedIPv6Host (component) {
|
|
756
|
+
const zone = component.ipv6Zone
|
|
757
|
+
// Without an ipv6Zone the single-"%" host form is genuinely ambiguous when
|
|
758
|
+
// the zone begins with "25", so we fall through to the best-effort heuristic
|
|
759
|
+
// (which matches the pre-existing behavior for hand-built components that do
|
|
760
|
+
// not carry a zone).
|
|
761
|
+
if (zone === undefined) return undefined
|
|
762
|
+
const host = component.host
|
|
763
|
+
const separator = host.indexOf('%')
|
|
764
|
+
if (separator === -1) return undefined
|
|
765
|
+
const address = host.slice(0, separator)
|
|
766
|
+
const escaped = address + '%25' + zone
|
|
767
|
+
const derived = normalizeIPv6('[' + escaped + ']')
|
|
768
|
+
if (derived.isIPV6 === true && derived.host === host) {
|
|
769
|
+
return '[' + escaped + ']'
|
|
770
|
+
}
|
|
771
|
+
return undefined
|
|
772
|
+
}
|
|
773
|
+
|
|
743
774
|
/**
|
|
744
775
|
* @param {import('../types/index').URIComponent} component
|
|
745
776
|
* @returns {string|undefined}
|
|
@@ -755,17 +786,30 @@ function recomposeAuthority (component) {
|
|
|
755
786
|
if (component.host !== undefined) {
|
|
756
787
|
let host = component.host
|
|
757
788
|
if (!isIPv4(host)) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
789
|
+
// A parse-time zone identifier is authoritative only while it still
|
|
790
|
+
// describes the current host. Re-deriving an IPv6 zone from the
|
|
791
|
+
// single-"%" component form is ambiguous when the zone begins with
|
|
792
|
+
// "25": it is misread as a %25 separator, rewriting e.g. zone
|
|
793
|
+
// "25eth0" into "eth0" (or destroying a zone of just "25"). A
|
|
794
|
+
// validated zone keeps parse, normalize, serialize and equal in
|
|
795
|
+
// agreement.
|
|
796
|
+
const zonedHost = recomposeZonedIPv6Host(component)
|
|
797
|
+
if (zonedHost !== undefined) {
|
|
798
|
+
host = zonedHost
|
|
767
799
|
} else {
|
|
768
|
-
|
|
800
|
+
let ipV6res = normalizeIPv6(host)
|
|
801
|
+
if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
|
|
802
|
+
// Decode only unreserved bytes, once. In particular, keep %25
|
|
803
|
+
// encoded so it cannot introduce a second escape during
|
|
804
|
+
// recomposition.
|
|
805
|
+
host = normalizePercentEncoding(host, true)
|
|
806
|
+
ipV6res = normalizeIPv6(host)
|
|
807
|
+
}
|
|
808
|
+
if (ipV6res.isIPV6 === true || ipV6res.isIPVFuture === true) {
|
|
809
|
+
host = `[${ipV6res.escapedHost}]`
|
|
810
|
+
} else {
|
|
811
|
+
host = reescapeHostDelimiters(host, false)
|
|
812
|
+
}
|
|
769
813
|
}
|
|
770
814
|
}
|
|
771
815
|
uriTokens.push(host)
|
package/package.json
CHANGED
|
@@ -119,6 +119,136 @@ test('IPv6 zone identifiers are validated correctly', (t) => {
|
|
|
119
119
|
t.end()
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
+
test('zoned IPv6 hosts beginning with "25" round-trip through parse/normalize/serialize/equal', (t) => {
|
|
123
|
+
const cases = [
|
|
124
|
+
// zones beginning with "25" (once ambiguous with a %25 separator)
|
|
125
|
+
['http://[fe80::1%2525]/', 'fe80::1%25', 'http://[fe80::1%2525]/'],
|
|
126
|
+
['http://[fe80::1%2525eth0]/', 'fe80::1%25eth0', 'http://[fe80::1%2525eth0]/'],
|
|
127
|
+
['http://[fe80::1%2525en1]/', 'fe80::1%25en1', 'http://[fe80::1%2525en1]/'],
|
|
128
|
+
// zones that do not begin with "25" must stay idempotent
|
|
129
|
+
['http://[fe80::1%25eth0]/', 'fe80::1%eth0', 'http://[fe80::1%25eth0]/'],
|
|
130
|
+
['http://[fe80::a%en1]/', 'fe80::a%en1', 'http://[fe80::a%25en1]/'],
|
|
131
|
+
['http://[fe80::a%25eth%2D0]/', 'fe80::a%eth%2D0', 'http://[fe80::a%25eth%2D0]/']
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
for (const [input, host, normalized] of cases) {
|
|
135
|
+
const parsed = fastURI.parse(input)
|
|
136
|
+
t.equal(parsed.error, undefined, `${input} parses without error`)
|
|
137
|
+
t.equal(parsed.host, host, `${input} exposes the expected host`)
|
|
138
|
+
t.equal(fastURI.normalize(input), normalized, `${input} normalizes to the canonical form`)
|
|
139
|
+
t.equal(fastURI.serialize(parsed), normalized, `${input} serializes to the canonical form`)
|
|
140
|
+
const reparsed = fastURI.parse(normalized)
|
|
141
|
+
t.equal(reparsed.error, undefined, `${input} canonical output reparses without error`)
|
|
142
|
+
t.equal(reparsed.host, host, `${input} parse-after-normalize is stable`)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// distinct zones must not be conflated by equal
|
|
146
|
+
t.equal(
|
|
147
|
+
fastURI.equal('http://[fe80::1%2525eth0]/', 'http://[fe80::1%25eth0]/'),
|
|
148
|
+
false,
|
|
149
|
+
'equal distinguishes zones "25eth0" and "eth0"'
|
|
150
|
+
)
|
|
151
|
+
t.equal(
|
|
152
|
+
fastURI.equal('http://[fe80::1%2525]/', 'http://[fe80::1%25eth0]/'),
|
|
153
|
+
false,
|
|
154
|
+
'equal distinguishes zones "25" and "eth0"'
|
|
155
|
+
)
|
|
156
|
+
// the same zone still compares equal
|
|
157
|
+
t.equal(
|
|
158
|
+
fastURI.equal('http://[fe80::1%2525eth0]/', 'http://[fe80::1%2525eth0]/'),
|
|
159
|
+
true,
|
|
160
|
+
'an identical zoned authority is equal'
|
|
161
|
+
)
|
|
162
|
+
t.equal(
|
|
163
|
+
fastURI.equal('http://[fe80::1%2525]/', 'http://[fe80::1%2525]/'),
|
|
164
|
+
true,
|
|
165
|
+
'zone "25" equals itself'
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
// resolve must preserve the zone too
|
|
169
|
+
t.equal(
|
|
170
|
+
fastURI.resolve('http://example.com/', 'http://[fe80::1%2525eth0]/path'),
|
|
171
|
+
'http://[fe80::1%2525eth0]/path',
|
|
172
|
+
'resolve preserves a zone beginning with "25"'
|
|
173
|
+
)
|
|
174
|
+
t.equal(
|
|
175
|
+
fastURI.resolve('http://[fe80::1%2525eth0]/', 'child'),
|
|
176
|
+
'http://[fe80::1%2525eth0]/child',
|
|
177
|
+
'resolve preserves a zoned base'
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
t.end()
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('serialize only trusts the parse-derived IPv6 zone while the host is unchanged', (t) => {
|
|
184
|
+
// Reassigning `host` after parse must take effect for serialize.
|
|
185
|
+
const parsed = fastURI.parse('http://[::1]/admin')
|
|
186
|
+
parsed.host = 'example.com'
|
|
187
|
+
t.equal(
|
|
188
|
+
fastURI.serialize(parsed),
|
|
189
|
+
'http://example.com/admin',
|
|
190
|
+
'a host reassigned after parse wins over the stale zone'
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
// A caller-supplied `ipv6Zone` that does not match `host` must be ignored.
|
|
194
|
+
const forged = fastURI.serialize({
|
|
195
|
+
scheme: 'http',
|
|
196
|
+
host: 'fe80::1%25en1',
|
|
197
|
+
ipv6Zone: 'eth0',
|
|
198
|
+
path: '/'
|
|
199
|
+
})
|
|
200
|
+
t.equal(forged, 'http://[fe80::1%25en1]/', 'a mismatched ipv6Zone is ignored')
|
|
201
|
+
t.equal(fastURI.parse(forged).host, 'fe80::1%en1', 'mismatched ipv6Zone cannot redirect the parsed host')
|
|
202
|
+
|
|
203
|
+
// A caller-supplied `ipv6Zone` on a non-zoned host must be ignored too.
|
|
204
|
+
const noZone = fastURI.serialize({
|
|
205
|
+
scheme: 'http',
|
|
206
|
+
host: 'good.example',
|
|
207
|
+
ipv6Zone: 'eth0',
|
|
208
|
+
path: '/'
|
|
209
|
+
})
|
|
210
|
+
t.equal(noZone, 'http://good.example/', 'ipv6Zone on a non-zoned host is ignored')
|
|
211
|
+
|
|
212
|
+
// Reassigning a zoned host to a different zone must recompute, not reuse.
|
|
213
|
+
const zoned = fastURI.parse('http://[fe80::1%2525eth0]/')
|
|
214
|
+
zoned.host = 'fe80::1%25en1'
|
|
215
|
+
t.equal(
|
|
216
|
+
fastURI.serialize(zoned),
|
|
217
|
+
'http://[fe80::1%25en1]/',
|
|
218
|
+
'rewriting the zone recomposes from the new host'
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
// A consistent caller-supplied zone is honored (explicit disambiguation).
|
|
222
|
+
const disambiguated = fastURI.serialize({
|
|
223
|
+
scheme: 'http',
|
|
224
|
+
host: 'fe80::1%25eth0',
|
|
225
|
+
ipv6Zone: '25eth0',
|
|
226
|
+
path: '/'
|
|
227
|
+
})
|
|
228
|
+
t.equal(
|
|
229
|
+
disambiguated,
|
|
230
|
+
'http://[fe80::1%2525eth0]/',
|
|
231
|
+
'a consistent ipv6Zone disambiguates the component host'
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
// Without ipv6Zone, an ambiguous single-"%" host falls back to the
|
|
235
|
+
// best-effort heuristic (documented behavior for hand-built components).
|
|
236
|
+
t.equal(
|
|
237
|
+
fastURI.serialize({ host: 'fe80::1%25eth0' }),
|
|
238
|
+
'//[fe80::1%25eth0]',
|
|
239
|
+
'an ambiguous host without ipv6Zone uses the best-effort heuristic'
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
// Mutating the host must not poison resolve either.
|
|
243
|
+
t.equal(
|
|
244
|
+
fastURI.resolve('http://example.com/', 'http://[fe80::1%2525eth0]/path'),
|
|
245
|
+
'http://[fe80::1%2525eth0]/path',
|
|
246
|
+
'resolve preserves the parse-derived zone'
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
t.end()
|
|
250
|
+
})
|
|
251
|
+
|
|
122
252
|
test('hosts with unbalanced or misplaced IP-literal brackets are rejected', (t) => {
|
|
123
253
|
const malformed = [
|
|
124
254
|
'http://[fe80',
|
package/types/index.d.ts
CHANGED
|
@@ -5,6 +5,22 @@ declare namespace fastUri {
|
|
|
5
5
|
scheme?: string;
|
|
6
6
|
userinfo?: string;
|
|
7
7
|
host?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Zone identifier of a zoned IPv6 host, e.g. `"eth0"` or `"25eth0"`. Set by
|
|
10
|
+
* `parse` for a bracketed IPv6 literal so `serialize`/`normalize` can
|
|
11
|
+
* reproduce the exact zone without re-deriving it from the ambiguous
|
|
12
|
+
* single-`%` form. It is validated on use, so a value that does not match
|
|
13
|
+
* `host` (for example after `host` is reassigned) is ignored.
|
|
14
|
+
*
|
|
15
|
+
* When building a component object by hand, set `ipv6Zone` to disambiguate
|
|
16
|
+
* a single-`%` host whose zone is ambiguous (a zone beginning with `25`
|
|
17
|
+
* is re-read as a `%25` separator). Without it, `serialize` falls back to
|
|
18
|
+
* a best-effort heuristic and may reinterpret such a zone, e.g. `{ host:
|
|
19
|
+
* "fe80::1%25eth0" }` serializes to `[fe80::1%25eth0]` (zone `eth0`), while
|
|
20
|
+
* `{ host: "fe80::1%25eth0", ipv6Zone: "25eth0" }` serializes to
|
|
21
|
+
* `[fe80::1%2525eth0]` (zone `25eth0`).
|
|
22
|
+
*/
|
|
23
|
+
ipv6Zone?: string;
|
|
8
24
|
port?: number | string;
|
|
9
25
|
path?: string;
|
|
10
26
|
query?: string;
|