summaryrefslogtreecommitdiff
path: root/tests/unit_node/http_test.ts
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-08-18 17:37:39 +0200
committerGitHub <noreply@github.com>2024-08-18 15:37:39 +0000
commit558d2a098bd20b3031139e37b088345c766e0b4e (patch)
treea932d7f4130f18a5a50ef19e271abc8327ce83cd /tests/unit_node/http_test.ts
parent35a17f38f6b32fe73ee6ef6d48cc774ddce998bd (diff)
fix(node/http): wrong `req.url` value (#25081)
This PR addresses a regression introduced in https://github.com/denoland/deno/pull/25021 that would cause the `req.url` parameter in Node's http server to always be a single character instead of the expected value. The regression was caused by effectively calling `.indexOf()` on an empty string and thus passing the wrong index for slicing. ```js "".indexOf("/") // -> -1 request.url.slice(-1) // effectively only giving us the last character ``` Fixes https://github.com/denoland/deno/issues/25080
Diffstat (limited to 'tests/unit_node/http_test.ts')
-rw-r--r--tests/unit_node/http_test.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index c0514eebd..ec20ec7d7 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -1539,3 +1539,21 @@ Deno.test("[node/http] ClientRequest PUT subarray", async () => {
await promise;
assertEquals(body, "world");
});
+
+Deno.test("[node/http] req.url equals pathname + search", async () => {
+ const { promise, resolve } = Promise.withResolvers<void>();
+
+ const server = http.createServer((req, res) => res.end(req.url));
+ server.listen(async () => {
+ const { port } = server.address() as net.AddressInfo;
+ const res = await fetch(`http://localhost:${port}/foo/bar?baz=1`);
+ const text = await res.text();
+ assertEquals(text, "/foo/bar?baz=1");
+
+ server.close(() => {
+ resolve();
+ });
+ });
+
+ await promise;
+});