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

$props aliasing allows invalid names #12626

Open
ottomated opened this issue Jul 26, 2024 · 7 comments
Open

$props aliasing allows invalid names #12626

ottomated opened this issue Jul 26, 2024 · 7 comments

Comments

@ottomated
Copy link
Contributor

Describe the bug

This is syntactically valid:

const { '=;123': alias } = $props();

but obviously, this is not:

<Component =;123="foo" />

Svelte should throw an error on invalid prop names here.

Reproduction

REPL

Logs

No response

System Info

n/a

Severity

annoyance

@dummdidumm
Copy link
Member

Related #5903

@FoHoOV
Copy link
Contributor

FoHoOV commented Jul 27, 2024

It allows something like this. Maybe a naming convention which makes sense (not this obviously) is using this "feature" somewhere. I think

<Component "=;123"={"foo"} />

should work though if this is going to be allowed.

@7nik
Copy link

7nik commented Jul 27, 2024

But you can easily pass a prop with any name using spreading:

let props = { "=;123": 42 };

<Component {...props} />

@7nik
Copy link

7nik commented Jul 27, 2024

I think

<Component "=;123"={"foo"} />

should work though if this is going to be allowed.

It will break the "compatibility" with HTML, and no one uses such names because they only cause headaches in other places. Those who do need it can still use prop spreading, prop aliasing, rest props, etc.

@ottomated
Copy link
Contributor Author

I think it's fine to allow some special characters here, but definitely not =. <Component ;123="foo" /> surprisingly does compile.

@7nik
Copy link

7nik commented Jul 27, 2024

The HTML standard disallows space, ", ', >, /, =, and obviously noncharacters. Anything other can be used in the attribute name.

@brunnerh
Copy link
Member

In addition, given that spreading works with anything, I don't think anything should be done here.

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

No branches or pull requests

5 participants