diff --git a/src/event/event.ts b/src/event/event.ts index 58240e5a..5fd4dad1 100644 --- a/src/event/event.ts +++ b/src/event/event.ts @@ -61,7 +61,14 @@ export class H3Event implements Pick { get path() { if (!this._path) { - this._path = this._originalPath.replace(DOUBLE_SLASH_RE, "/"); + const hasQuery = this._originalPath.includes("?"); + + if (hasQuery) { + const [basePath, query] = this._originalPath.split("?"); + this._path = basePath.replace(DOUBLE_SLASH_RE, "/") + "?" + query; + } else { + this._path = this._originalPath.replace(DOUBLE_SLASH_RE, "/"); + } } return this._path; } diff --git a/test/event.test.ts b/test/event.test.ts index a98731dc..f468c8a2 100644 --- a/test/event.test.ts +++ b/test/event.test.ts @@ -102,4 +102,18 @@ describe("Event", () => { expect(result.text).toBe("200"); }); + + it("can read path with URL", async () => { + app.use( + "/", + eventHandler((event) => { + expect(event.path).toBe("/?url=https://example.com"); + return "200"; + }) + ); + + const result = await request.get("/?url=https://example.com"); + + expect(result.text).toBe("200"); + }); });