Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Allow more permissive form input name and ID #53981

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

Open
wants to merge 5 commits into
base: 7.3
Choose a base branch
Loading
from

Conversation

asispts
Copy link
Contributor

@asispts asispts commented Feb 17, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #53977
Fix #53976
License MIT

Changes in this PR:

  1. testNameAcceptsOnlyNamesValidAsIdsInHtml4 has been split into 2 functions: testInvalidFormInputName and testValidFormInputName,
  2. Allow input names to start with hyphens ("-") and colons (":"),
  3. Disallow isindex as an input name.
  4. Allow more permissive form input id

@carsonbot carsonbot added this to the 7.1 milestone Feb 17, 2024
@asispts asispts force-pushed the fix/issue-53977-form-name branch 2 times, most recently from 8b45fe1 to 3239eb8 Compare February 17, 2024 12:49
@asispts asispts changed the title Allow more permissive form input name Allow more permissive form input name and ID Feb 19, 2024
@asispts asispts changed the title Allow more permissive form input name and ID [Form] Allow more permissive form input name and ID Feb 19, 2024
@asispts
Copy link
Contributor Author

asispts commented Feb 23, 2024

PR is ready.

doctrine-bridge test fails because it still uses old BaseTypeTestCase code, instead of the updated one in this PR.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some tweaks please

nicolas-grekas added a commit that referenced this pull request Mar 19, 2024
…sispts)

This PR was merged into the 5.4 branch.

Discussion
----------

[DoctrineBridge] Drop a test case in `EntityTypeTest`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

This PR will drop a test case as suggested by `@nicolas`-grekas. See: #53981 (comment)

Commits
-------

f6506aa Drop test case
@asispts asispts force-pushed the fix/issue-53977-form-name branch from d6740c2 to 0312392 Compare March 19, 2024 19:33
@asispts asispts force-pushed the fix/issue-53977-form-name branch from 0312392 to 534ea18 Compare March 19, 2024 19:37
@asispts
Copy link
Contributor Author

asispts commented Mar 19, 2024

Rebased and ready

*/
final public static function isValidName(?string $name): bool
{
return '' === $name || null === $name || preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/D', $name);
return ('' === $name || null === $name || preg_match('/^[a-zA-Z0-9_\-:]*$/D', $name)) && 'isindex' !== $name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we fordbid isindex now? This is a BC break if I don’t miss anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because isindex is not allowed in HTML5.

Yeah, it's a BC break. Any idea how to handle this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let‘s deprecate it in 7.1 and don’t accept it in 8.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong though. Most of the Symfony form names could use isindex without issue. The HTML restriction would only forbid us to generate a full name equal to isindex, while root[isindex] is perfectly valid in HTML (remember that the Symfony form name is not used directly as the HTML name, but is involved in generating it)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding that it's not only isindex, but also _charset_, see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-name

An ASCII case-insensitive match for the name _charset_ is special: if used as the name of a Hidden control with no value attribute, then during submission the value attribute is automatically given a value consisting of the submission character encoding.

@carsonbot carsonbot changed the title [Form] Allow more permissive form input name and ID Allow more permissive form input name and ID Mar 22, 2024
// Periods are allowed by the HTML4 spec, but disallowed by us
// because they break the generated property paths
['a.', 'Symfony\Component\Form\Exception\InvalidArgumentException'],

// Contrary to the HTML4 spec, we allow names starting with a
// number, otherwise naming fields by collection indices is not
// possible.
// For root forms, leading digits will be stripped from the
// "id" attribute to produce valid HTML4.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still accurate ?

['isINDEX'],

// This value shouldn't be allowed.
// However, many tests in Form component require empty name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is wrong to me. The fullname of a non-compound field should not be empty (as HTML form inputs will need a non-empty name). But this is not what is validated by the validation you run here.

For instance, a perfectly valid use case is to have an empty name for the root form, so that names of fields look like field1 and not root[field1].

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
// Strip leading underscores and digits. These are allowed in
// form names, but not in HTML4 ID attributes.
// https://www.w3.org/TR/html401/struct/global#adef-id
$id = ltrim($id, '_0123456789');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be kept IMO as written in #53976 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this change is kept (which I think is good - see my answer at #53976 (comment) ), then it's a BC break and therefore should target v8.0.

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot
Copy link
Member

fabpot commented Mar 29, 2025

@asispts This PR looks stale, are you still willing to work on this PR?

@carsonbot carsonbot changed the title Allow more permissive form input name and ID [Form] Allow more permissive form input name and ID Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.