Skip to content

Replace parseurl with WHATWG URL API #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/express/mock-request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const accepts = require('accepts');
const typeis = require('type-is');
const parseRange = require('range-parser');
const parse = require('parseurl');
const { isIP } = require('net');
const fresh = require('fresh');

Expand Down Expand Up @@ -119,7 +118,7 @@ defineGetter(req, 'subdomains', function subdomains() {
});

defineGetter(req, 'path', function path() {
return parse(this).pathname;
return new URL(this).pathname;
Copy link
Preview

Copilot AI Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'new URL(this)' may throw an error if 'this' does not contain an absolute URL. Consider providing a valid absolute URL string or a base URL as the second parameter to ensure proper parsing.

Suggested change
return new URL(this).pathname;
const baseUrl = `${this.protocol || 'http'}://${this.host || 'localhost'}`;
return new URL(this.url, baseUrl).pathname;

Copilot uses AI. Check for mistakes.

});

defineGetter(req, 'hostname', function hostname() {
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"merge-descriptors": "^1.0.1",
"methods": "^1.1.2",
"mime": "^1.3.4",
"parseurl": "^1.3.3",
"range-parser": "^1.2.0",
"type-is": "^1.6.18"
},
Expand Down