Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 526163c

Browse filesBrowse files
AyushG3112MylesBorins
authored andcommitted
url: introduce URL_FLAGS_IS_DEFAULT_SCHEME_PORT flag
Introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag which is retured when the parser detects that the port passed is the default port for that scheme. PR-URL: #20479 Fixes: #20465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent ed5f253 commit 526163c
Copy full SHA for 526163c

File tree

Expand file treeCollapse file tree

4 files changed

+18
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+18
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
URL_FLAGS_HAS_PATH,
4747
URL_FLAGS_HAS_QUERY,
4848
URL_FLAGS_HAS_USERNAME,
49+
URL_FLAGS_IS_DEFAULT_SCHEME_PORT,
4950
URL_FLAGS_SPECIAL,
5051
kFragment,
5152
kHost,
@@ -276,7 +277,7 @@ function onParsePortComplete(flags, protocol, username, password,
276277
function onParseHostComplete(flags, protocol, username, password,
277278
host, port, path, query, fragment) {
278279
onParseHostnameComplete.apply(this, arguments);
279-
if (port !== null)
280+
if (port !== null || ((flags & URL_FLAGS_IS_DEFAULT_SCHEME_PORT) !== 0))
280281
onParsePortComplete.apply(this, arguments);
281282
}
282283

Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,8 @@ void URL::Parse(const char* input,
17491749
}
17501750
// the port is valid
17511751
url->port = NormalizePort(url->scheme, static_cast<int>(port));
1752+
if (url->port == -1)
1753+
url->flags |= URL_FLAGS_IS_DEFAULT_SCHEME_PORT;
17521754
buffer.clear();
17531755
} else if (has_state_override) {
17541756
// TODO(TimothyGu): Similar case as above.
Collapse file

‎src/node_url.h‎

Copy file name to clipboardExpand all lines: src/node_url.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ using v8::Value;
5050
XX(URL_FLAGS_HAS_HOST, 0x80) \
5151
XX(URL_FLAGS_HAS_PATH, 0x100) \
5252
XX(URL_FLAGS_HAS_QUERY, 0x200) \
53-
XX(URL_FLAGS_HAS_FRAGMENT, 0x400)
53+
XX(URL_FLAGS_HAS_FRAGMENT, 0x400) \
54+
XX(URL_FLAGS_IS_DEFAULT_SCHEME_PORT, 0x800) \
5455

5556
enum url_parse_state {
5657
kUnknownState = -1,
Collapse file

‎test/fixtures/url-setter-tests.js‎

Copy file name to clipboardExpand all lines: test/fixtures/url-setter-tests.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* The following tests are copied from WPT. Modifications to them should be
44
upstreamed first. Refs:
5-
https://github.com/w3c/web-platform-tests/blob/ed4bb727ed/url/setters_tests.json
5+
https://github.com/w3c/web-platform-tests/blob/f0fe479/url/setters_tests.json
66
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
77
*/
88
module.exports =
@@ -727,6 +727,17 @@ module.exports =
727727
"port": "80"
728728
}
729729
},
730+
{
731+
"comment": "Port number is removed if new port is scheme default and existing URL has a non-default port",
732+
"href": "http://example.net:8080",
733+
"new_value": "example.com:80",
734+
"expected": {
735+
"href": "http://example.com/",
736+
"host": "example.com",
737+
"hostname": "example.com",
738+
"port": ""
739+
}
740+
},
730741
{
731742
"comment": "Stuff after a / delimiter is ignored",
732743
"href": "http://example.net/path",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.