瀏覽代碼

merged branch canni/throw_exception_on_form_name_circulal_ref (PR #2675)

Commits
-------

36cebf0 Fix infinite loop on circullar reference in form factory

Discussion
----------

[BugFix][Form]Throw exception on form name circulal ref

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Closes: #2673

When FormType method `getName()` returns the same value as `getParent()` we're asking about trouble, and land into infinite loop.
Fabien Potencier 13 年之前
父節點
當前提交
af2713261d
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      src/Symfony/Component/Form/FormFactory.php

+ 4 - 0
src/Symfony/Component/Form/FormFactory.php

@@ -220,6 +220,10 @@ class FormFactory implements FormFactoryInterface
 
         while (null !== $type) {
             if ($type instanceof FormTypeInterface) {
+                if ($type->getName() == $type->getParent($options)) {
+                    throw new FormException(sprintf('The "%s" form type name ("%s") is not valid. It contains circullar reference to parent type name ("%s")', get_class($type), $type->getName(), $type->getParent($options)));
+                }
+
                 $this->addType($type);
             } else {
                 $type = $this->getType($type);