From 1a012a285c81bccd3820c78bae4e73d3c821a990 Mon Sep 17 00:00:00 2001 From: Allan Kimmer Jensen Date: Mon, 17 Feb 2025 12:15:17 +0100 Subject: [PATCH 1/2] chore: Replace parseurl with WHATWG URL API More information here: https://github.com/e18e/ecosystem-issues/issues/160 --- lib/express/mock-request.js | 3 +-- package-lock.json | 16 +--------------- package.json | 1 - 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/express/mock-request.js b/lib/express/mock-request.js index 57b28f7..3f08c9a 100644 --- a/lib/express/mock-request.js +++ b/lib/express/mock-request.js @@ -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'); @@ -119,7 +118,7 @@ defineGetter(req, 'subdomains', function subdomains() { }); defineGetter(req, 'path', function path() { - return parse(this).pathname; + return new URL(this).pathname; }); defineGetter(req, 'hostname', function hostname() { diff --git a/package-lock.json b/package-lock.json index b198942..d3e170e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "node-mocks-http", - "version": "1.16.1", + "version": "1.16.2", "license": "MIT", "dependencies": { "accepts": "^1.3.7", @@ -16,7 +16,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" }, @@ -4893,14 +4892,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "engines": { - "node": ">= 0.8" - } - }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -9948,11 +9939,6 @@ "lines-and-columns": "^1.1.6" } }, - "parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" - }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", diff --git a/package.json b/package.json index 0d72425..cc64972 100644 --- a/package.json +++ b/package.json @@ -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" }, From c975c2b392c95461d4ebb25322fdfb87cda5e730 Mon Sep 17 00:00:00 2001 From: Allan Kimmer Jensen Date: Thu, 30 Apr 2026 11:06:33 +0200 Subject: [PATCH 2/2] fix: use this.url with base URL in path getter The URL constructor requires an absolute URL string, not a request object. Use this.url with a constructed base URL to handle relative paths like '/some/path?name=foo' that parseurl previously handled. Also fix pre-existing eslint no-extraneous-dependencies error in type declaration tests. --- lib/express/mock-request.js | 2 +- test/lib/http-mock.test-d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/express/mock-request.js b/lib/express/mock-request.js index 3f08c9a..8128399 100644 --- a/lib/express/mock-request.js +++ b/lib/express/mock-request.js @@ -118,7 +118,7 @@ defineGetter(req, 'subdomains', function subdomains() { }); defineGetter(req, 'path', function path() { - return new URL(this).pathname; + return new URL(this.url, `${this.protocol || 'http'}://${this.hostname || 'localhost'}`).pathname; }); defineGetter(req, 'hostname', function hostname() { diff --git a/test/lib/http-mock.test-d.ts b/test/lib/http-mock.test-d.ts index cd34c45..cc0baaa 100644 --- a/test/lib/http-mock.test-d.ts +++ b/test/lib/http-mock.test-d.ts @@ -1,7 +1,7 @@ import { IncomingMessage as NodeRequest, OutgoingMessage as NodeResponse } from 'http'; // eslint-disable-next-line import/no-unresolved import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; -// eslint-disable-next-line import/no-unresolved +// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies import { Request as ExpressRequest, Response as ExpressResponse } from 'express'; import { createMocks, createRequest, createResponse, MockRequest, MockResponse, Mocks } from '../../lib/http-mock';