Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
asispts wants to merge5 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromasispts:fix/issue-53977-form-name

Conversation

asispts
Copy link
Contributor

@asisptsasispts commentedFeb 17, 2024
edited by OskarStark
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#53977
Fix#53976
LicenseMIT

Changes in this PR:

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

@carsonbotcarsonbot added this to the7.1 milestoneFeb 17, 2024
@asisptsasisptsforce-pushed thefix/issue-53977-form-name branch 2 times, most recently from8b45fe1 to3239eb8CompareFebruary 17, 2024 12:49
@asisptsasispts changed the titleAllow more permissive form input nameAllow more permissive form input name and IDFeb 19, 2024
@asisptsasispts changed the titleAllow more permissive form input name and ID[Form] Allow more permissive form input name and IDFeb 19, 2024
@asispts
Copy link
ContributorAuthor

PR is ready.

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

Copy link
Member

@nicolas-grekasnicolas-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 requestMar 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       | MITThis PR will drop a test case as suggested by `@nicolas`-grekas. See:#53981 (comment)Commits-------f6506aa Drop test case
@asisptsasisptsforce-pushed thefix/issue-53977-form-name branch fromd6740c2 to0312392CompareMarch 19, 2024 19:33
@asisptsasisptsforce-pushed thefix/issue-53977-form-name branch from0312392 to534ea18CompareMarch 19, 2024 19:37
@asispts
Copy link
ContributorAuthor

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 fordbidisindex now? This is a BC break if I don’t miss anything.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Becauseisindex 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 useisindex without issue. The HTML restriction would only forbid us to generate afull name equal toisindex, whileroot[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 onlyisindex, but also_charset_, seehttps://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-name

AnASCII case-insensitive match for the name_charset_ is special: if used as the name of aHidden control with novalue attribute, then during submission thevalue attribute is automatically given a value consisting of the submission character encoding.

@carsonbotcarsonbot changed the title[Form] Allow more permissive form input name and IDAllow more permissive form input name and IDMar 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 likefield1 and notroot[field1].

@xabbuhxabbuh modified the milestones:7.1,7.2May 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.

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

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

@carsonbotcarsonbot changed the titleAllow more permissive form input name and ID[Form] Allow more permissive form input name and IDMar 30, 2025
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@ThomasLandauerThomasLandauerThomasLandauer left review comments

@xabbuhxabbuhxabbuh requested changes

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

[Form] Too strict validation of form fieldnames (HTML4 instead of HTML5) [Form] Over-sanitization of form'sid attributes
8 participants
@asispts@fabpot@nicolas-grekas@stof@ThomasLandauer@xabbuh@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp