mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Implements a new `req.query` getter that parses URL query parameters into nested objects and arrays, matching the behavior of Express.js and Ruby on Rails.
## Features
- Parses simple parameters: `?name=john&age=30` → `{ name: "john", age: "30" }`
- Supports nested objects: `?user[name]=alice` → `{ user: { name: "alice" } }`
- Supports arrays: `?ids[]=1&ids[]=2` → `{ ids: ["1", "2"] }`
- Supports indexed arrays: `?items[0]=a&items[1]=b` → `{ items: ["a", "b"] }`
- Handles complex nesting: `?users[0][name]=alice` → `{ users: [{ name: "alice" }] }`
## Implementation
- Extracted parsing logic to BunRequestParams.cpp for maintainability
- Added PropertyCallback getter to JSBunRequest
- Uses null prototype objects to prevent prototype pollution
- Ignores __proto__ keys for security
- Only available when using routes with Bun.serve()
## Testing
- Added comprehensive test suite with 20 test cases
- Exposed parseQueryParams in bun:internal-for-testing for unit testing
- Tests cover edge cases including sparse arrays, type conflicts, and security
This brings Bun's request handling closer to Express/Rails conventions, making it easier for developers to migrate existing applications.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>