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

Lock down attribute name and property name patterns. #199

Open
theengineear opened this issue Nov 8, 2024 · 0 comments
Open

Lock down attribute name and property name patterns. #199

theengineear opened this issue Nov 8, 2024 · 0 comments

Comments

@theengineear
Copy link
Collaborator

theengineear commented Nov 8, 2024

Attributes

HTML attributes are case-insensitive. There is no reason to support uppercase letters. We can support lowercase, alphanumeric, and hyphens. However, we should consider restricting leading / trailing hyphens and leading digits.

// accepted
html`<div foo="${bar}"></div>`
html`<div f-o-o="${bar}"></div>`
html`<div f00="${bar}"></div>`

// rejected
html`<div 1foo="${bar}"></div>`  // leading digit
html`<div f_o_o="${bar}"></div>` // characters other than “[a-z0-9-]”
html`<div -foo="${bar}"></div>`  // leading hyphen
html`<div foo-="${bar}"></div>`  // trailing hyphen

Properties

There is no such think in HTML as “properties” — they are completely provided by our DSL. However, we can look to the specification for valid variable names and common conventions to guide us. Property names should only contain alphanumeric characters (uppercase is ok) and underscores, but leading / trailing underscores should be forbidden, leading digits should not be allowed, and leading uppercase letters should not be allowed.

// accepted
html`<div .foo="${bar}"></div>`
html`<div .fOo="${bar}"></div>`
html`<div .f_o_o="${bar}"></div>`
html`<div .f00="${bar}"></div>`

// rejected
html`<div .1foo="${bar}"></div>`  // leading digit
html`<div .f-o-o="${bar}"></div>` // characters other than “[a-zA-Z0-9_]”
html`<div .Foo="${bar}"></div>`   // leading uppercase character
html`<div ._foo="${bar}"></div>`  // leading underscore
html`<div .foo_="${bar}"></div>`  // trailing underscore

Context

I recently went to port some code that was using a property like _internal, and that cannot be bound via ._internal="${whatever}". At first, I thought it would be better to allow it… but then I thought… it’s really not internal, it’s on the public interface. I am waffling a bit on how restrictive / flexible to be here.

@theengineear theengineear changed the title Discussion: What patterns should be allowed for attributes and properties. Lock down attribute name and property name patterns. Dec 28, 2024
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

1 participant