[prev in list] [next in list] [prev in thread] [next in thread]
List: pear-cvs
Subject: [PEAR-CVS] =?utf-8?q?svn:_/pear/packages/HTML=5FQuickForm2/trunk/_HTML/QuickForm2/Container/Group.ph
From: Alexey_Borzov <avb () php ! net>
Date: 2012-06-21 18:44:44
Message-ID: svn-avb-1340304284-326287-716211555 () svn ! php ! net
[Download RAW message or body]
avb Thu, 21 Jun 2012 18:44:44 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=326287
Log:
Leftover 'foo' in grouped element's name when group named 'foo[foo]' is renamed (bug \
#19477), made Group::renameChild() a bit easier to read
Bug: http://pear.php.net/bugs/19477 (unknown)
Changed paths:
U pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Container/Group.php
U pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Container/GroupTest.php
Modified: pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Container/Group.php
===================================================================
--- pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Container/Group.php 2012-06-21 \
17:39:39 UTC (rev 326286)
+++ pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Container/Group.php 2012-06-21 \
18:44:44 UTC (rev 326287) @@ -214,30 +214,24 @@
protected function renameChild(HTML_QuickForm2_Node $element)
{
$tokens = explode('[', str_replace(']', '', $element->getName()));
- if ($this === $element->getContainer()) {
- // Child has already been renamed by its group before
- if (!is_null($this->previousName) && $this->previousName !== '') {
- $gtokens = explode('[', str_replace(']', '', $this->previousName));
- $pos = array_search(end($gtokens), $tokens);
- if (!is_null($pos)) {
- $tokens = array_slice($tokens, $pos+1);
- }
+ // Child has already been renamed by its group before
+ if ($this === $element->getContainer() && strlen($this->previousName)) {
+ $gtokens = explode('[', str_replace(']', '', $this->previousName));
+ if ($gtokens === array_slice($tokens, 0, count($gtokens))) {
+ array_splice($tokens, 0, count($gtokens));
}
}
- if (is_null($this->name) || $this->name === '') {
- if (is_null($this->previousName) || $this->previousName === '') {
- return $element;
- } else {
- $elname = $tokens[0];
- unset($tokens[0]);
- foreach ($tokens as $v) {
- $elname .= '['.$v.']';
- }
+
+ if (strlen($this->name)) {
+ $element->setName($this->name . '[' . implode('][', $tokens) . ']');
+ } elseif (strlen($this->previousName)) {
+ $elname = array_shift($tokens);
+ foreach ($tokens as $token) {
+ $elname .= '[' . $token . ']';
}
- } else {
- $elname = $this->getName().'['.implode('][', $tokens).']';
+ $element->setName($elname);
}
- $element->setName($elname);
+
return $element;
}
Modified: pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Container/GroupTest.php
===================================================================
--- pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Container/GroupTest.php 2012-06-21 \
17:39:39 UTC (rev 326286)
+++ pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Container/GroupTest.php 2012-06-21 \
18:44:44 UTC (rev 326287) @@ -404,5 +404,18 @@
$group->setValue(array('red', 'blue'));
$this->assertEquals(array('red', 'blue'), $group->getValue());
}
+
+ /**
+ * Renaming groups with names like 'foo[foo]' or '1[1]' resulted in wrong names \
for grouped elements + * @link http://pear.php.net/bugs/bug.php?id=19477
+ */
+ public function testBug19477()
+ {
+ $group = new HTML_QuickForm2_Container_Group('foo[foo]');
+ $text = $group->addElement(new HTML_QuickForm2_Element_InputText('bar'));
+ $group->setName('test[foo][foo]');
+
+ $this->assertEquals('test[foo][foo][bar]', $text->getName());
+ }
}
?>
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic