Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: introduce URL_FLAGS_IS_DEFAULT_SCHEME_PORT flag #20479

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const {
URL_FLAGS_HAS_PATH,
URL_FLAGS_HAS_QUERY,
URL_FLAGS_HAS_USERNAME,
URL_FLAGS_IS_DEFAULT_SCHEME_PORT,
URL_FLAGS_SPECIAL,
kFragment,
kHost,
Expand Down Expand Up @@ -276,7 +277,7 @@ function onParsePortComplete(flags, protocol, username, password,
function onParseHostComplete(flags, protocol, username, password,
host, port, path, query, fragment) {
onParseHostnameComplete.apply(this, arguments);
if (port !== null)
if (port !== null || ((flags & URL_FLAGS_IS_DEFAULT_SCHEME_PORT) !== 0))
onParsePortComplete.apply(this, arguments);
}

Expand Down
2 changes: 2 additions & 0 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,8 @@ void URL::Parse(const char* input,
}
// the port is valid
url->port = NormalizePort(url->scheme, static_cast<int>(port));
if (url->port == -1)
url->flags |= URL_FLAGS_IS_DEFAULT_SCHEME_PORT;
buffer.clear();
} else if (has_state_override) {
// TODO(TimothyGu): Similar case as above.
Expand Down
3 changes: 2 additions & 1 deletion src/node_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ using v8::Value;
XX(URL_FLAGS_HAS_HOST, 0x80) \
XX(URL_FLAGS_HAS_PATH, 0x100) \
XX(URL_FLAGS_HAS_QUERY, 0x200) \
XX(URL_FLAGS_HAS_FRAGMENT, 0x400)
XX(URL_FLAGS_HAS_FRAGMENT, 0x400) \
XX(URL_FLAGS_IS_DEFAULT_SCHEME_PORT, 0x800) \

enum url_parse_state {
kUnknownState = -1,
Expand Down
13 changes: 12 additions & 1 deletion test/fixtures/url-setter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* The following tests are copied from WPT. Modifications to them should be
upstreamed first. Refs:
https://github.com/w3c/web-platform-tests/blob/ed4bb727ed/url/setters_tests.json
https://github.com/w3c/web-platform-tests/blob/f0fe479/url/setters_tests.json
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
module.exports =
Expand Down Expand Up @@ -727,6 +727,17 @@ module.exports =
"port": "80"
}
},
{
"comment": "Port number is removed if new port is scheme default and existing URL has a non-default port",
"href": "http://example.net:8080",
"new_value": "example.com:80",
"expected": {
"href": "http://example.com/",
"host": "example.com",
"hostname": "example.com",
"port": ""
}
},
{
"comment": "Stuff after a / delimiter is ignored",
"href": "http://example.net/path",
Expand Down