Skip to content

Commit 7b16aed

Browse files
committed
Ensure the URL API roundtrips for opaque paths
Follows whatwg/url#728.
1 parent f252843 commit 7b16aed

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
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 [48f1e79](https://github.com/whatwg/url/commit/48f1e79e5d930bf95eaffbbe6c7ae5ed81d397a0).
7+
whatwg-url is currently up to date with the URL spec up to commit [fdaa0e5](https://github.com/whatwg/url/commit/fdaa0e5a3790693a82f578d7373f216d8fef9ac8).
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ exports.implementation = class URLImpl {
171171
if (v === "") {
172172
url.query = null;
173173
this._query._list = [];
174+
this._potentiallyStripTrailingSpacesFromAnOpaquePath();
174175
return;
175176
}
176177

@@ -195,6 +196,7 @@ exports.implementation = class URLImpl {
195196
set hash(v) {
196197
if (v === "") {
197198
this._url.fragment = null;
199+
this._potentiallyStripTrailingSpacesFromAnOpaquePath();
198200
return;
199201
}
200202

@@ -206,4 +208,20 @@ exports.implementation = class URLImpl {
206208
toJSON() {
207209
return this.href;
208210
}
211+
212+
_potentiallyStripTrailingSpacesFromAnOpaquePath() {
213+
if (!usm.hasAnOpaquePath(this._url)) {
214+
return;
215+
}
216+
217+
if (this._url.fragment !== null) {
218+
return;
219+
}
220+
221+
if (this._url.query !== null) {
222+
return;
223+
}
224+
225+
this._url.path = this._url.path.replace(/\u0020+$/u, "");
226+
}
209227
};

lib/URLSearchParams-impl.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ exports.implementation = class URLSearchParamsImpl {
3131

3232
_updateSteps() {
3333
if (this._url !== null) {
34-
let query = urlencoded.serializeUrlencoded(this._list);
35-
if (query === "") {
36-
query = null;
34+
let serializedQuery = urlencoded.serializeUrlencoded(this._list);
35+
if (serializedQuery === "") {
36+
serializedQuery = null;
37+
}
38+
39+
this._url._url.query = serializedQuery;
40+
41+
if (serializedQuery === null) {
42+
this._url._potentiallyStripTrailingSpacesFromAnOpaquePath();
3743
}
38-
this._url._url.query = query;
3944
}
4045
}
4146

scripts/get-latest-platform-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ process.on("unhandledRejection", err => {
1818
// 1. Go to https://github.com/web-platform-tests/wpt/tree/master/url
1919
// 2. Press "y" on your keyboard to get a permalink
2020
// 3. Copy the commit hash
21-
const commitHash = "0a187bc16933e67dfb8755935143a6dd5a9e12f2";
21+
const commitHash = "d9d78543960a04ea8ad8f1aa3c7536b6a9a87d9a";
2222

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

0 commit comments

Comments
 (0)