Skip to content

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Feb 21, 2024
1 parent 5a6e8c4 commit c88ea5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,16 @@ function wrap(protocols) {

function noop() { /* empty */ }

function parseUrl(input) {
function parseUrl(input, base) {
var parsed;
/* istanbul ignore else */
if (useNativeURL) {
parsed = new URL(input);
parsed = new URL(input, base);
}
else {
if (base) {
input = url.resolve(base, input);
}
// Ensure the URL is valid and absolute
parsed = validateUrl(url.parse(input));
if (!isString(parsed.protocol)) {
Expand All @@ -567,10 +570,10 @@ function parseUrl(input) {
}

function resolveUrl(relative, base) {
// Ensure that any non-ascii characters are escaped correctly as a valid URI
relative = encodeURI(Buffer.from(relative, 'binary').toString('utf8'))
/* istanbul ignore next */
return useNativeURL ? new URL(relative, base) : parseUrl(url.resolve(base, relative));
const parsed = parseUrl(relative, base);
// Ensure that any non-ascii characters in path are escaped correctly as a valid URI
parsed.pathname = parseUrl(encodeURI(Buffer.from(relative, "binary").toString("utf8")), base).pathname;
return parsed;
}

function validateUrl(input) {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe("follow-redirects", function () {
app.get("/a", redirectsTo("/b"));
app.get("/b", (_, res) => {
res.statusCode = 302;
res.set('Location', "http://localhost:3600/¢");
res.set("Location", "http://localhost:3600/¢");
res.end();
});
app.get("/%C2%A2", redirectsTo("/d"));
Expand Down

0 comments on commit c88ea5c

Please sign in to comment.