fast-uri 2.4.1 → 2.4.2

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 CHANGED
@@ -267,7 +267,7 @@ function parseWithStatus (uri, opts) {
267
267
  if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {
268
268
  // convert Unicode IDN -> ASCII IDN
269
269
  try {
270
- parsed.host = URL.domainToASCII(parsed.host.toLowerCase())
270
+ parsed.host = new URL('http://' + parsed.host).hostname
271
271
  } catch (e) {
272
272
  parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
273
273
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-uri",
3
3
  "description": "Dependency free RFC 3986 URI toolbox",
4
- "version": "2.4.1",
4
+ "version": "2.4.2",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "types": "types/index.d.ts",
@@ -132,3 +132,31 @@ test('normalize does not double-decode %2540 into a live @', (t) => {
132
132
  t.plan(1)
133
133
  t.not(parsed.host, 'trusted.com@evil.com', 'http://trusted.com%2540evil.com/')
134
134
  })
135
+
136
+ test('parse canonicalises IDN / Unicode hosts to their ASCII form', (t) => {
137
+ const cases = [
138
+ {
139
+ input: 'http://127。0。0。1/',
140
+ expectedHost: '127.0.0.1',
141
+ description: 'full-width ideographic stops as octet separators'
142
+ },
143
+ {
144
+ input: 'http://example.com/',
145
+ expectedHost: 'example.com',
146
+ description: 'fullwidth e as first letter'
147
+ },
148
+ {
149
+ input: 'http://納豆.example.org/',
150
+ expectedHost: 'xn--99zt52a.example.org',
151
+ description: 'CJK label requiring punycode'
152
+ }
153
+ ]
154
+
155
+ t.plan(cases.length * 2)
156
+
157
+ cases.forEach(({ input, expectedHost, description }) => {
158
+ const parsed = fastURI.parse(input)
159
+ t.notOk(parsed.error, `parse should not set error: ${description}`)
160
+ t.equal(parsed.host, expectedHost, `host canonicalised to ASCII: ${description}`)
161
+ })
162
+ })