From edfe997b06afe42b558c5da08f651289eec5c49c Mon Sep 17 00:00:00 2001 From: Jerome TAMARELLE Date: Fri, 5 Jul 2013 15:25:47 +0200 Subject: [PATCH] [widget] Fix array to string convertion when using renderId with an array as value --- lib/widget/sfWidgetForm.class.php | 4 ++-- test/unit/widget/sfWidgetFormTest.php | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/widget/sfWidgetForm.class.php b/lib/widget/sfWidgetForm.class.php index 65ca76d89..a79968257 100644 --- a/lib/widget/sfWidgetForm.class.php +++ b/lib/widget/sfWidgetForm.class.php @@ -244,7 +244,7 @@ public function generateId($name, $value = null) // check to see if we have an array variable for a field name if (strstr($name, '[')) { - $name = str_replace(array('[]', '][', '[', ']'), array((null !== $value ? '_'.$value : ''), '_', '_', ''), $name); + $name = str_replace(array('[]', '][', '[', ']'), array((null !== $value && !is_array($value) ? '_'.$value : ''), '_', '_', ''), $name); } if (false !== strpos($this->getOption('id_format'), '%s')) @@ -330,7 +330,7 @@ protected function translate($text, array $parameters = array()) * @param array $parameters The values to replace the placeholders * * @return array The translated texts - * + * * @see sfWidgetFormSchemaFormatter::translate() */ protected function translateAll(array $texts, array $parameters = array()) diff --git a/test/unit/widget/sfWidgetFormTest.php b/test/unit/widget/sfWidgetFormTest.php index 68998a88e..43199ab03 100644 --- a/test/unit/widget/sfWidgetFormTest.php +++ b/test/unit/widget/sfWidgetFormTest.php @@ -10,7 +10,7 @@ require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); -$t = new lime_test(34); +$t = new lime_test(35); class MyWidgetForm extends sfWidgetForm { @@ -106,12 +106,13 @@ public function generateId($name, $value = null) $t->is($w->generateId('foo[]'), 'id_for_foo_works', '->generateId() removes the [] from the name'); $t->is($w->generateId('foo[bar][]'), 'id_for_foo_bar_works', '->generateId() replaces [] with _'); $t->is($w->generateId('foo[bar][]', 'test'), 'id_for_foo_bar_test_works', '->generateId() takes the value into account if provided'); -$t->is($w->generateId('_foo[bar][]', 'test'), 'id_for__foo_bar_test_works', '->generateId() leaves valid ids'); +$t->is($w->generateId('_foo[bar][]', 'test'), 'id_for__foo_bar_test_works', '->generateId() leaves valid ids'); $w->setIdFormat('id'); $t->is($w->generateId('foo[bar][]', 'test'), 'foo_bar_test', '->generateId() returns the name if the id format does not contain %s'); +$t->is($w->generateId('foo[bar][]', array('test1', 'test2')), 'foo_bar', '->generateId() ignore the value if not a string'); $w->setIdFormat('%s'); -$t->is($w->generateId('_foo[bar][]', 'test'), 'foo_bar_test', '->generateId() removes invalid characters'); -$t->is($w->generateId('_foo@bar'), 'foo_bar', '->generateId() removes invalid characters'); -$t->is($w->generateId('_____foo@bar'), 'foo_bar', '->generateId() removes invalid characters'); +$t->is($w->generateId('_foo[bar][]', 'test'), 'foo_bar_test', '->generateId() removes invalid characters'); +$t->is($w->generateId('_foo@bar'), 'foo_bar', '->generateId() removes invalid characters'); +$t->is($w->generateId('_____foo@bar'), 'foo_bar', '->generateId() removes invalid characters');