Skip to content

Conversation

@zoriya
Copy link
Contributor

@zoriya zoriya commented Jan 4, 2026

If we have a t.Transform(t.Array()) in a query param and only pass one value, the value is never Decoded.

minimal repro:

import { Elysia, t } from "elysia";

new Elysia()
	.get(
		"/",
		({ query }) => {
			return query;
		},
		{
			query: t.Object({
				a: t
					.Transform(t.Array(t.String()))
					.Decode((x) => {
						return { decoded: x };
					})
					.Encode((x) => {
						throw new Error("nop");
					}),
				b: t.Optional(
					t
						.Transform(t.String())
						.Decode((x) => {
							return { decoded: x };
						})
						.Encode((x) => {
							throw new Error("nop");
						}),
				),
			}),
		},
	)
   .listen(3000);

doing curl http://localhost:3000?a=toto,tata we get the expected decoded value:

{
  "a": {
    "decoded": [
      "toto",
      "taat"
    ]
  }
}

doing it with a single value also works curl http://localhost:3000?a=toto

{
  "a": {
    "decoded": [
      "toto"
    ]
  }
}

but adding another transformed query params break it for a single value: curl http://localhost:3000?a=toto&b=toto

{
  "a": [
    "toto"
  ],
  "b": {
    "decoded": "toto"
  }
}

while adding a second value works: curl http://localhost:3000?a=toto,tata&b=toto

{
  "a": {
    "decoded": [
      "toto",
      "tata"
    ]
  },
  "b": {
    "decoded": "toto"
  }
}

After this patch is applied, this works too! curl 'http://localhost:8901?a=toto&b=toto'

{
  "a": {
    "decoded": [
      "toto"
    ]
  },
  "b": {
    "decoded": "toto"
  }
}

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency in array query decoding for single-value string inputs. String values are now processed through the same validation pipeline as comma-separated values, ensuring uniform handling across all input types.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

Walkthrough

ArrayQuery.Decode now routes single-element string inputs through compiler.Decode by passing [value], instead of returning the raw [value], making decoding consistent with comma-separated inputs.

Changes

Cohort / File(s) Change Summary
Array Validation Consistency
src/type-system/index.ts
ArrayQuery.Decode changed to call compiler.Decode([value]) for single-element string inputs rather than returning the raw [value], aligning single-value decoding with comma-separated decoding logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 One string, one path, now validated true,
No raw escapes when decoding is due,
Through compiler's eye, both single and bunch,
Consistency hopped—a satisfying crunch! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Decode single values in ArrayQuery' directly and accurately describes the main change: applying compiler-based decoding to single-element string inputs in ArrayQuery, which fixes the reported bug where single values weren't decoded correctly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e16dc82 and abf62bd.

📒 Files selected for processing (1)
  • src/type-system/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/type-system/index.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/elysiajs/elysia@1655

commit: abf62bd

If we have a `t.Transform(t.Array())` in a query param and only pass one value, the value is never Decoded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant