8000 [Form] Allow more permissive form input name and ID by asispts · Pull Request #53981 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow leading underscore and digits in Form ID
  • Loading branch information
asispts committed Mar 19, 2024
commit 673b0b79e59c80e1e3489e83b065adac337d090d
5 changes: 0 additions & 5 deletions src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public function buildView(FormView $view, FormInterface $form, array $options):
$id = \is_string($options['form_attr']) ? $options['form_attr'] : $name;
$fullName = $name;
$uniqueBlockPrefix = '_'.$blockName;

// 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.

}

$blockPrefixes = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2084,12 +2084,12 @@ public function testPassIdAndNameToView()
$this->assertEquals('name', $view->vars['full_name']);
}

public function testStripLeadingUnderscoresAndDigitsFromId()
public function testAllowLeadingUnderscoreAndDigitsFromId()
{
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null)
->createView();

$this->assertEquals('name', $view->vars['id']);
$this->assertEquals('_09name', $view->vars['id']);
$this->assertEquals('_09name', $view->vars['name']);
$this->assertEquals('_09name', $view->vars['full_name']);
}
Expand Down
0