Skip to content

Commit 64bdf3a

Browse files
authored
Use URLSearchParams to construct wpt.fyi API URLs (#154)
This should be a no-op change, but takes care of escaping of names and values in a simpler way, and if it should be needed for the page token.
1 parent 4a456ab commit 64bdf3a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/runs.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const {advanceDateToSkipBadDataIfNecessary} = require('../bad-ranges');
99
const RUNS_API = 'https://wpt.fyi/api/runs';
1010

1111
function apiURL(options = {}) {
12-
const queryParts = Object.entries(options).map(([name, value]) => {
12+
const url = new URL(RUNS_API);
13+
for (let [name, value] of Object.entries(options)) {
1314
if (Array.isArray(value)) {
1415
value = value.join(',');
1516
}
16-
return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
17-
});
18-
const query = queryParts.join('&');
19-
return `${RUNS_API}?${query}`;
17+
url.searchParams.set(name, value);
18+
}
19+
return url;
2020
}
2121

2222
async function get(options) {
@@ -64,7 +64,8 @@ async function* getIterator(options) {
6464
break;
6565
}
6666
previousUrl = url;
67-
url = `${RUNS_API}?page=${token}`;
67+
url = new URL(RUNS_API);
68+
url.searchParams.set('page', token);
6869
}
6970
}
7071

0 commit comments

Comments
 (0)