You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
h3's getQuery parses boolean types as strings. ufo's getQuery parses them as booleans. This causes issues when passing a generic that accepts booleans.
The reproduction test provided above (added as part of utils.test.ts) fails with the following assertion error:
AssertionError: expected '{"statusCode":500,"stack":["Assertion…' to be '200' // Object.is equality
- Expected
+ Received
- 200
+ {"statusCode":500,"stack":["AssertionError: expected { bool: 'true' } to match object { bool: true }","at Proxy.<anonymous> (file:///home/bacongobbler/code/github.com/unjs/h3/node_modules/.pnpm/@vitest+expect@1.6.0/node_modules/@vitest/expect/dist/index.js:951:13)","at Proxy.<anonymous> (file:///home/bacongobbler/code/github.com/unjs/h3/node_modules/.pnpm/@vitest+expect@1.6.0/node_modules/@vitest/expect/dist/index.js:800:17)","at Proxy.methodWrapper (/home/bacongobbler/code/github.com/unjs/h3/node_modules/.pnpm/chai@4.4.1/node_modules/chai/lib/chai/utils/addMethod.js:57:25)","at Object.handler (/home/bacongobbler/code/github.com/unjs/h3/test/utils.test.ts:222:25)","at Object.handler (/home/bacongobbler/code/github.com/unjs/h3/src/app/_handler.ts:51:33)","at processTicksAndRejections (node:internal/process/task_queues:95:5)","at Server.nodeHandler (/home/bacongobbler/code/github.com/unjs/h3/src/adapters/node/utils.ts:27:25)"]}
This causes issues down the road because query.bool is a boolean type, not a string type.
Additional context
test case confirming bool: "true" (string type) is expected in h3:
Thanks for reporting issue. Upcoming h3 v2 is being based on URLSearchParams as parser which only accepts string as query values therefore you should base your types to only rely on string as possible value.
You can use destr also to safely parse json values.
Environment
h3
1.12.0, 2.0.0-beta.0, mainReproduction
Describe the bug
h3
'sgetQuery
parses boolean types as strings.ufo
'sgetQuery
parses them as booleans. This causes issues when passing a generic that accepts booleans.The reproduction test provided above (added as part of utils.test.ts) fails with the following assertion error:
This causes issues down the road because
query.bool
is a boolean type, not a string type.Additional context
test case confirming
bool: "true"
(string type) is expected in h3:h3/test/utils.test.ts
Line 203 in 1be630e
test case confirming
bool: true
(boolean type) is expected inufo
: https://github.com/unjs/ufo/blob/666091db37a03dc871e25d3621aeff1b89648196/test/query.test.ts#L16-L18Logs
No response
The text was updated successfully, but these errors were encountered: