mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
[autofix.ci] apply automated fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { bunEnv, bunExe } from "harness";
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
console.log("Test file loaded");
|
||||
|
||||
@@ -17,7 +16,7 @@ test("req.query - simple parameters", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?name=john&age=30&active=true`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
name: "john",
|
||||
age: "30",
|
||||
@@ -39,7 +38,7 @@ test("req.query - empty query string", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({});
|
||||
});
|
||||
|
||||
@@ -57,7 +56,7 @@ test("req.query - URL encoded values", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?message=Hello%20World&special=%40%23%24%25`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
message: "Hello World",
|
||||
special: "@#$%",
|
||||
@@ -78,7 +77,7 @@ test("req.query - Rails-style nested objects", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?user[name]=john&user[age]=30&user[email]=john@example.com`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
user: {
|
||||
name: "john",
|
||||
@@ -100,9 +99,11 @@ test("req.query - Rails-style deeply nested objects", async () => {
|
||||
},
|
||||
});
|
||||
|
||||
const res = await fetch(`${server.url}?person[address][street]=123%20Main&person[address][city]=Portland&person[name]=Bob`);
|
||||
const res = await fetch(
|
||||
`${server.url}?person[address][street]=123%20Main&person[address][city]=Portland&person[name]=Bob`,
|
||||
);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
person: {
|
||||
address: {
|
||||
@@ -128,7 +129,7 @@ test("req.query - Rails-style arrays with empty brackets", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?ids[]=1&ids[]=2&ids[]=3`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
ids: ["1", "2", "3"],
|
||||
});
|
||||
@@ -148,7 +149,7 @@ test("req.query - Rails-style indexed arrays", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?items[0]=apple&items[1]=banana&items[2]=orange`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
items: ["apple", "banana", "orange"],
|
||||
});
|
||||
@@ -170,7 +171,7 @@ test("req.query - Rails-style indexed arrays", async () => {
|
||||
//
|
||||
// const res = await fetch(`${server.url}?user[tags][]=admin&user[tags][]=developer&user[name]=alice`);
|
||||
// const data = await res.json();
|
||||
//
|
||||
//
|
||||
// expect(data).toEqual({
|
||||
// user: {
|
||||
// tags: ["admin", "developer"],
|
||||
@@ -193,7 +194,7 @@ test("req.query - duplicate keys (last wins)", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?color=red&color=blue&color=green`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
// In simple key-value pairs, last value wins
|
||||
expect(data).toEqual({
|
||||
color: "green",
|
||||
@@ -214,7 +215,7 @@ test("req.query - mixed simple and nested parameters", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?simple=value&nested[key]=nestedValue&array[]=1&array[]=2`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
simple: "value",
|
||||
nested: {
|
||||
@@ -238,7 +239,7 @@ test("req.query - numeric-looking keys", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?123=numeric&0=zero&normal=text`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
"123": "numeric",
|
||||
"0": "zero",
|
||||
@@ -260,7 +261,7 @@ test("req.query - empty values", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?empty=&also_empty&has_value=yes`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
empty: "",
|
||||
also_empty: "",
|
||||
@@ -282,7 +283,7 @@ test("req.query - complex nested structure", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?users[0][name]=alice&users[0][age]=25&users[1][name]=bob&users[1][age]=30`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
users: [
|
||||
{ name: "alice", age: "25" },
|
||||
@@ -305,13 +306,13 @@ test("req.query - __proto__ is ignored for security", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?__proto__=evil&user[__proto__]=bad&normal=ok`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
// __proto__ keys should be ignored
|
||||
expect(data).toEqual({
|
||||
normal: "ok",
|
||||
user: {},
|
||||
});
|
||||
|
||||
|
||||
// Verify prototype wasn't polluted
|
||||
expect(Object.prototype.hasOwnProperty("evil")).toBe(false);
|
||||
});
|
||||
@@ -336,7 +337,7 @@ test("req.query - null prototype object", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?test=value`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data.hasNullProto).toBe(true);
|
||||
expect(data.query).toEqual({ test: "value" });
|
||||
});
|
||||
@@ -355,7 +356,7 @@ test("req.query - special characters in keys", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?key%20with%20spaces=value&symbols!%40%23=test`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data).toEqual({
|
||||
"key with spaces": "value",
|
||||
"symbols!@#": "test",
|
||||
@@ -377,7 +378,7 @@ test("req.query - works only with routes (Bun.serve)", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?test=value`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
// Without routes, req.query won't be available (regular Request, not BunRequest)
|
||||
expect(data.hasQuery).toBe(false);
|
||||
});
|
||||
@@ -388,7 +389,7 @@ test("req.query - with routes", async () => {
|
||||
routes: {
|
||||
"/test": {
|
||||
GET(req) {
|
||||
return Response.json({
|
||||
return Response.json({
|
||||
hasQuery: "query" in req,
|
||||
query: req.query,
|
||||
});
|
||||
@@ -399,7 +400,7 @@ test("req.query - with routes", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}/test?foo=bar`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
expect(data.hasQuery).toBe(true);
|
||||
expect(data.query).toEqual({ foo: "bar" });
|
||||
});
|
||||
@@ -418,7 +419,7 @@ test("req.query - sparse indexed arrays", async () => {
|
||||
|
||||
const res = await fetch(`${server.url}?arr[0]=first&arr[2]=third&arr[5]=sixth`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
// Sparse arrays will have null in JSON for missing indices
|
||||
expect(data).toEqual({
|
||||
arr: ["first", null, "third", null, null, "sixth"],
|
||||
@@ -441,9 +442,9 @@ test("req.query - array and object type conflict", async () => {
|
||||
// the first type wins and conflicting params are ignored
|
||||
const res = await fetch(`${server.url}?items[]=array&items[key]=object`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
// First param established items as array, so object notation is ignored
|
||||
expect(data).toEqual({
|
||||
items: ["array"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { parseQueryParams } from "bun:internal-for-testing";
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
test("parseQueryParams - simple parameters", () => {
|
||||
const result = parseQueryParams("name=john&age=30&active=true");
|
||||
@@ -108,7 +108,7 @@ test("parseQueryParams - __proto__ is ignored for security", () => {
|
||||
expect(result).toEqual({
|
||||
normal: "ok",
|
||||
});
|
||||
|
||||
|
||||
// Verify prototype wasn't polluted
|
||||
expect(Object.prototype.hasOwnProperty("evil")).toBe(false);
|
||||
});
|
||||
@@ -135,4 +135,4 @@ test("parseQueryParams - array and object type conflict", () => {
|
||||
expect(result).toEqual({
|
||||
items: ["array"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user