fast-uri 3.1.2 → 3.1.3
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/index.js +1 -1
- package/package.json +1 -1
- package/test/security.test.js +28 -0
package/index.js
CHANGED
|
@@ -305,7 +305,7 @@ function parseWithStatus (uri, opts) {
|
|
|
305
305
|
if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {
|
|
306
306
|
// convert Unicode IDN -> ASCII IDN
|
|
307
307
|
try {
|
|
308
|
-
parsed.host = URL
|
|
308
|
+
parsed.host = new URL('http://' + parsed.host).hostname
|
|
309
309
|
} catch (e) {
|
|
310
310
|
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
|
|
311
311
|
}
|
package/package.json
CHANGED
package/test/security.test.js
CHANGED
|
@@ -131,3 +131,31 @@ test('normalize does not double-decode %2540 into a live @', (t) => {
|
|
|
131
131
|
t.plan(1)
|
|
132
132
|
t.notEqual(parsed.host, 'trusted.com@evil.com', 'http://trusted.com%2540evil.com/')
|
|
133
133
|
})
|
|
134
|
+
|
|
135
|
+
test('parse canonicalises IDN / Unicode hosts to their ASCII form', (t) => {
|
|
136
|
+
const cases = [
|
|
137
|
+
{
|
|
138
|
+
input: 'http://127。0。0。1/',
|
|
139
|
+
expectedHost: '127.0.0.1',
|
|
140
|
+
description: 'full-width ideographic stops as octet separators'
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
input: 'http://example.com/',
|
|
144
|
+
expectedHost: 'example.com',
|
|
145
|
+
description: 'fullwidth e as first letter'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
input: 'http://納豆.example.org/',
|
|
149
|
+
expectedHost: 'xn--99zt52a.example.org',
|
|
150
|
+
description: 'CJK label requiring punycode'
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
t.plan(cases.length * 2)
|
|
155
|
+
|
|
156
|
+
cases.forEach(({ input, expectedHost, description }) => {
|
|
157
|
+
const parsed = fastURI.parse(input)
|
|
158
|
+
t.notOk(parsed.error, `parse should not set error: ${description}`)
|
|
159
|
+
t.equal(parsed.host, expectedHost, `host canonicalised to ASCII: ${description}`)
|
|
160
|
+
})
|
|
161
|
+
})
|