Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie schema validation doesn't work with aot: true #641

Open
bogeychan opened this issue May 16, 2024 · 4 comments
Open

Cookie schema validation doesn't work with aot: true #641

bogeychan opened this issue May 16, 2024 · 4 comments
Labels
bug Something isn't working pending Should be resolved in next release

Comments

@bogeychan
Copy link
Contributor

What version of Elysia.JS is running?

1.0.20

What platform is your computer?

No response

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

const app = new Elysia()
  .get(
    "/",
    ({ cookie: { hello } }) => {
      console.log(
        `The value of the "hello" cookie is ${
          hello.value
        } and it is of type ${typeof hello.value}`
      );
      return "Hello Elysia";
    },
    { cookie: t.Cookie({ hello: t.String() }) }
  )
  .listen(8080);

console.log(`${app.server!.url}`);

What is the expected behavior?

No response

What do you see instead?

  1. Doesn't throw an ValidationError when the hello cookie does not exist
  2. If I set the hello cookie equal to the string 123, it gets parsed as a number even though I explicitly stated it's of type string

Additional information

Reported on discord


works as expected if you configure:

new Elysia({ aot: false })
@bogeychan bogeychan added the bug Something isn't working label May 16, 2024
@SaltyAom
Copy link
Member

Should be fix on 321a7c5, published under 1.0.21

@SaltyAom SaltyAom added the pending Should be resolved in next release label May 21, 2024
@bogeychan
Copy link
Contributor Author

bogeychan commented May 22, 2024

@SaltyAom, It still converts the cookie value to number even though I specified t.String as the type

nvm, bun installed wrong version 😭

@bogeychan
Copy link
Contributor Author

bogeychan commented May 22, 2024

BUT i got an error when passing 123:

{
  "type": "validation",
  "on": "cookie",
  "property": "/hello",
  "message": "Expected string",
  "expected": {
    "hello": ""
  },
  "found": {
    "hello": 123
  },
  "errors": [
    {
      "type": 54,
      "schema": {
        "type": "string"
      },
      "path": "/hello",
      "value": 123,
      "message": "Expected string"
    }
  ]
}

@bogeychan
Copy link
Contributor Author

same bug with new Elysia({ aot: false })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending Should be resolved in next release
Projects
None yet
Development

No branches or pull requests

2 participants