Skip to content

Commit 9fc4125

Browse files
alxndrsnspwoodcock
authored andcommitted
Stop using legacy url.parse() (getodk#1459)
Deprecated in node v18.13, v20: > Stability: 0 - Deprecated: Use the WHATWG URL API instead. See: https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost
1 parent ffcde53 commit 9fc4125

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/util/http.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// Helper functions that relate to the HTTP/service layer of the application.
1111

12-
const { parse, URL } = require('url');
12+
const { URL } = require('url');
1313
const { map, tryCatch } = require('ramda');
1414
const { isBlank } = require('./util');
1515
const Option = require('./option');
@@ -24,7 +24,10 @@ const isTrue = (x) => (!isBlank(x) && typeof x === 'string' && (x.toLowerCase()
2424
const isFalse = (x) => (!isBlank(x) && typeof x === 'string' && (x.toLowerCase() === 'false'));
2525

2626
// Returns just the pathname of the URL, omitting querystring and other non-path decoration.
27-
const urlPathname = (x) => parse(x).pathname;
27+
const urlPathname = (url) => {
28+
if (typeof url !== 'string') throw new Error(`The "url" argument must be of type string.`);
29+
return new URL(url, 'http://example.test').pathname;
30+
};
2831

2932
const urlDecode = tryCatch(map(Option.of, decodeURIComponent), Option.none);
3033

0 commit comments

Comments
 (0)