…em arrays
String fields (default is a string) were pre-parsed before validation, so
?q=true became a boolean and ?q=[1] became an array. Zod string schemas then
reset the field to its default, and createSearchParamsSchema turned [1] into
"1" and {"a":1} into "[object Object]". String fields are now read as
written.
Array fields only used the comma fallback when the value had a comma, so
?tags=a stayed a string and failed validation. Any non-empty value is now
split, so ?tags=a gives ["a"].
The per-value conversion shared by extractParamValues and
extractSelectiveParamValues now lives in one helper.
Fixes svecosystem#436
Fixes #436
What was wrong
extractParamValuesandextractSelectiveParamValuesturned"true"/"false"into booleans and[...]/{...}into parsed JSON for every field, before the schema had a say. String fields are written to the URL as-is, so a string liketrueor[1]came back as the wrong type:z.string().default("")failed validation and reset to""(typingtrueinto a bound input cleared it).createSearchParamsSchemastring fields ranString()on the parsed value, so[1]became"1"and{"a":1}became"[object Object]".Array fields only used the comma fallback when the value had a comma, so
?tags=astayed"a"and fell back to[].Fix
extractSchemaInfonow also collectsstringFields(fields whose default is a string, minus codec fields). Values for these are read verbatim.?tags=agives["a"].?tags=still stays"", like before.convertParamValuehelper so the two can't drift again. Behavior for other fields is unchanged (including a bad JSON value staying a plain string).Tests
extract-param-values.test.ts: string fields keeptrue/false/[1]/{"a":1}/[]/{}, other fields still convert, single-item and empty array values.validate-search-params.test.ts: the cases from the issue with bothcreateSearchParamsSchemaand Zod.7 new tests fail on
mainand pass here.vitest --run: 250 unit tests pass (the browser project needs a local Chromium, which I don't have).prettier --check,oxlint,eslintandsvelte-checkare clean.I left the changeset out since CONTRIBUTING says maintainers add those; happy to add one if you'd like.