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: expose WHATWG url.origin as ASCII #13126

Closed
wants to merge 1 commit 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
9 changes: 3 additions & 6 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ function toUSVString(val) {
// Refs: https://html.spec.whatwg.org/multipage/browsers.html#concept-origin-opaque
const kOpaqueOrigin = 'null';

// Refs:
// - https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin
// - https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin
function serializeTupleOrigin(scheme, host, port, unicode = true) {
const unicodeHost = unicode ? domainToUnicode(host) : host;
return `${scheme}//${unicodeHost}${port === null ? '' : `:${port}`}`;
// Refs: https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin
function serializeTupleOrigin(scheme, host, port) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin or quote the Note: There used to also be a Unicode serialization of an origin. However, it was never widely adopted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to? This function is purely internal, and there is no remnant from the previous Unicode serialization that needs explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the standard kept a "there was something here", I thought we could emulate.
But I yield to your decision.

return `${scheme}//${host}${port === null ? '' : `:${port}`}`;
}

// This class provides the internal state of a URL object. An instance of this
Expand Down
11 changes: 6 additions & 5 deletions test/fixtures/url-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/* WPT Refs:
https://github.com/w3c/web-platform-tests/blob/0f26c418a5/url/urltestdata.json
https://github.com/w3c/web-platform-tests/blob/8df7c9c215/url/urltestdata.json
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
module.exports =
Expand Down Expand Up @@ -3679,7 +3679,7 @@ module.exports =
"input": "http://你好你好",
"base": "http://other.com/",
"href": "http://xn--6qqa088eba/",
"origin": "http://你好你好",
"origin": "http://xn--6qqa088eba",
"protocol": "http:",
"username": "",
"password": "",
Expand All @@ -3694,7 +3694,7 @@ module.exports =
"input": "https://faß.ExAmPlE/",
"base": "about:blank",
"href": "https://xn--fa-hia.example/",
"origin": "https://faß.example",
"origin": "https://xn--fa-hia.example",
"protocol": "https:",
"username": "",
"password": "",
Expand All @@ -3709,6 +3709,7 @@ module.exports =
"input": "sc://faß.ExAmPlE/",
"base": "about:blank",
"href": "sc://fa%C3%9F.ExAmPlE/",
"origin": "null",
"protocol": "sc:",
"username": "",
"password": "",
Expand Down Expand Up @@ -4617,7 +4618,7 @@ module.exports =
"input": "ftp://%e2%98%83",
"base": "about:blank",
"href": "ftp://xn--n3h/",
"origin": "ftp://",
"origin": "ftp://xn--n3h",
"protocol": "ftp:",
"username": "",
"password": "",
Expand All @@ -4632,7 +4633,7 @@ module.exports =
"input": "https://%e2%98%83",
"base": "about:blank",
"href": "https://xn--n3h/",
"origin": "https://",
"origin": "https://xn--n3h",
"protocol": "https:",
"username": "",
"password": "",
Expand Down