8000 [Form] added a form type name validator · symfony/symfony@7eec2ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 7eec2ca

Browse files
committed
[Form] added a form type name validator
1 parent db415db commit 7eec2ca

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Symfony/Component/Form/FormFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function addType(FormTypeInterface $type)
9191
{
9292
$this->loadTypeExtensions($type);
9393

94+
$this->validateFormTypeName($type);
95+
9496
$this->types[$type->getName()] = $type;
9597
}
9698

@@ -377,6 +379,8 @@ private function loadType($name)
377379

378380
$this->loadTypeExtensions($type);
379381

382+
$this->validateFormTypeName($type);
383+
380384
$this->types[$name] = $type;
381385
}
382386

@@ -398,4 +402,11 @@ private function loadTypeExtensions(FormTypeInterface $type)
398402

399403
$type->setExtensions($typeExtensions);
400404
}
405+
406+
private function validateFormTypeName(FormTypeInterface $type)
407+
{
408+
if (!preg_match('/^[a-z0-9_]+$/i', $type->getName())) {
409+
throw new FormException(sprintf('The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".', get_class($type), $type->getName()));
410+
}
411+
}
401412
}

0 commit comments

Comments
 (0)
0