forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: ensure host setter matches parse for file url
Technically, file URLs are not permitted to have a port. There is currently an ambiguity in the URL spec. In the current spec having a port in a file URL is undefined behavior. In the current implementation, the port is ignored and handled as if it were part of the host name. This will be changing once the ambiguity is resolved in the spec. The spec change may involve either ignoring the port if specified or throwing with an Invalid URL error if the port is specified. For now, this test verifies the currently implemented behavior. Fixes: nodejs#10608
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// Technically, file URLs are not permitted to have a port. There is | ||
// currently an ambiguity in the URL spec. In the current spec | ||
// having a port in a file URL is undefined behavior. In the current | ||
// implementation, the port is ignored and handled as if it were part | ||
// of the host name. This will be changing once the ambiguity is | ||
// resolved in the spec. The spec change may involve either ignoring the | ||
// port if specified or throwing with an Invalid URL error if the port | ||
// is specified. For now, this test verifies the currently implemented | ||
// behavior. | ||
|
||
require('../common'); | ||
const URL = require('url').URL; | ||
const assert = require('assert'); | ||
|
||
const u = new URL('file://example.net:80/foo'); | ||
|
||
assert.strictEqual(u.hostname, 'example.net:80'); | ||
assert.strictEqual(u.port, ''); | ||
|
||
u.host = 'example.com:81'; | ||
|
||
assert.strictEqual(u.hostname, 'example.com:81'); | ||
assert.strictEqual(u.port, ''); | ||
|
||
u.hostname = 'example.org:81'; | ||
|
||
assert.strictEqual(u.hostname, 'example.org'); | ||
assert.strictEqual(u.port, ''); |