elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.46k stars 223 forks source link

Confusion about wildcards in file extensions #892

Open Huliiiiii opened 1 week ago

Huliiiiii commented 1 week ago

What version of Elysia is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

This is how we check for file extensions: https://github.com/elysiajs/elysia/blob/90071866076617de1693c0edd50e62b6aa7f763b/src/type-system.ts#L207-L227

But we have wildcard file types: https://github.com/elysiajs/elysia/blob/90071866076617de1693c0edd50e62b6aa7f763b/src/type-system.ts#L103-L157

If we use wildcards in the extension, type checking will always fail:

function check(options, type) {
  if (options.extension)
    if (typeof options.extension === "string") {
      if (!type.startsWith(options.extension)) return false
    } else {
      for (let i = 0; i < options.extension.length; i++)
        if (type.startsWith(options.extension[i])) return true

      return false
    }
}

check({ extension: ["image/*"] }, "image/jpeg") // false
check({ extension: ["image/*"] }, "image/png") // false

Is this intentional?

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

No response

K4leri commented 1 week ago

@Huliiiiii Already done https://github.com/elysiajs/elysia/pull/877