Skip to content

Commit c923241

Browse files
committed
Ensure opaque paths always roundtrip
Follows whatwg/url@6c78200. Closes #293.
1 parent 45174a8 commit c923241

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe
44

55
## Specification conformance
66

7-
whatwg-url is currently up to date with the URL spec up to commit [cfae7c4](https://github.com/whatwg/url/commit/cfae7c4ed1851886390e132fc336b653fada9123).
7+
whatwg-url is currently up to date with the URL spec up to commit [6c78200](https://github.com/whatwg/url/commit/6c782003a2d53b1feecd072d1006eb8f1d65fb2d).
88

99
For `file:` URLs, whose [origin is left unspecified](https://url.spec.whatwg.org/#concept-url-origin), whatwg-url chooses to use a new opaque origin (which serializes to `"null"`).
1010

lib/URL-impl.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ exports.implementation = class URLImpl {
195195
if (v === "") {
196196
url.query = null;
197197
this._query._list = [];
198-
this._potentiallyStripTrailingSpacesFromAnOpaquePath();
199198
return;
200199
}
201200

@@ -220,7 +219,6 @@ exports.implementation = class URLImpl {
220219
set hash(v) {
221220
if (v === "") {
222221
this._url.fragment = null;
223-
this._potentiallyStripTrailingSpacesFromAnOpaquePath();
224222
return;
225223
}
226224

@@ -232,20 +230,4 @@ exports.implementation = class URLImpl {
232230
toJSON() {
233231
return this.href;
234232
}
235-
236-
_potentiallyStripTrailingSpacesFromAnOpaquePath() {
237-
if (!usm.hasAnOpaquePath(this._url)) {
238-
return;
239-
}
240-
241-
if (this._url.fragment !== null) {
242-
return;
243-
}
244-
245-
if (this._url.query !== null) {
246-
return;
247-
}
248-
249-
this._url.path = this._url.path.replace(/\u0020+$/u, "");
250-
}
251233
};

lib/URLSearchParams-impl.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ exports.implementation = class URLSearchParamsImpl {
3737
}
3838

3939
this._url._url.query = serializedQuery;
40-
41-
if (serializedQuery === null) {
42-
this._url._potentiallyStripTrailingSpacesFromAnOpaquePath();
43-
}
4440
}
4541
}
4642

lib/url-state-machine.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,13 @@ URLStateMachine.prototype["parse opaque path"] = function parseOpaquePath(c) {
10601060
} else if (c === p("#")) {
10611061
this.url.fragment = "";
10621062
this.state = "fragment";
1063+
} else if (c === p(" ")) {
1064+
const remaining = this.input[this.pointer + 1];
1065+
if (remaining === p("?") || remaining === p("#")) {
1066+
this.url.path += "%20";
1067+
} else {
1068+
this.url.path += " ";
1069+
}
10631070
} else {
10641071
// TODO: Add: not a URL code point
10651072
if (!isNaN(c) && c !== p("%")) {

scripts/get-latest-platform-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const path = require("path");
1313
// 1. Go to https://github.com/web-platform-tests/wpt/tree/master/url
1414
// 2. Press "y" on your keyboard to get a permalink
1515
// 3. Copy the commit hash
16-
const commitHash = "d86fcc9e8764155485975a2a9bbfc5ec4aa9e75b";
16+
const commitHash = "072413fba2fef3c16877673af78215174ca8f7c2";
1717

1818
const urlPrefix = `https://raw.githubusercontent.com/web-platform-tests/wpt/${commitHash}/url/`;
1919
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");

0 commit comments

Comments
 (0)