From c3166d9f3a483cd54afda0e0a1fe9ee2b28dba09 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Tue, 30 Jul 2013 10:21:34 +0800 Subject: [PATCH] Fix bug #947 --- ext/tag.c | 6 ++++-- unit-tests/TagTest.php | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ext/tag.c b/ext/tag.c index 6b504d349df..466a497e97d 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -700,8 +700,10 @@ PHP_METHOD(Phalcon_Tag, _inputFieldChecked){ PHALCON_OBS_VAR(current_value); phalcon_array_fetch_string(¤t_value, params, SL("value"), PH_NOISY); - if (PHALCON_IS_EQUAL(current_value, value)) { - phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); + if (Z_TYPE_P(value) != IS_NULL) { + if (PHALCON_IS_EQUAL(current_value, value)) { + phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); + } } } else { /** diff --git a/unit-tests/TagTest.php b/unit-tests/TagTest.php index 996c5e5d014..e29e6a7bee7 100644 --- a/unit-tests/TagTest.php +++ b/unit-tests/TagTest.php @@ -71,4 +71,34 @@ public function testIssue744() $this->assertTrue(true); } } -} \ No newline at end of file + + public function testIssue947() + { + use Phalcon\Tag; + $di = new Phalcon\DI\FactoryDefault(); + Tag::setDI($di); + + $html = Tag::radioField(array( + 'test', + 'value' => 1, + 'checked' => 'checked' + )); + $pos = strpos($html, 'checked="checked"'); + $this->assertTrue($pos !== FALSE); + + $html = Tag::radioField(array( + 'test', + 'value' => 0 + )); + $pos = strpos($html, 'checked="checked"'); + $this->assertTrue($pos === FALSE); + + Tag::setDefault("test", "0"); + $html = Tag::radioField(array( + 'test', + 'value' => 0 + )); + $pos = strpos($html, 'checked="checked"'); + $this->assertTrue($pos !== FALSE); + } +}