Skip to content

Commit

Permalink
Fixing issue in FormHelper where CURRENT_TIMESTAMP or other invalid d…
Browse files Browse the repository at this point in the history
…ata could cause a notice error. Fixes #1508
  • Loading branch information
markstory committed Feb 5, 2011
1 parent f381234 commit cf50cbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1843,8 +1843,11 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
if ($time[0] == 0 && $timeFormat == '12') {
$time[0] = 12;
}
$hour = $time[0];
$min = $time[1];
$hour = $min = null;
if (isset($time[1])) {
$hour = $time[0];
$min = $time[1];
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -4494,6 +4494,16 @@ function testDatetimeWithDefault() {
$this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
}

/**
* test that bogus non-date time data doesn't cause errors.
*
* @return void
*/
function testDateTimeWithBogusData() {
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', 'CURRENT_TIMESTAMP');
$this->assertNoPattern('/selected="selected">\d/', $result);
}

/**
* testFormDateTimeMulti method
*
Expand Down

0 comments on commit cf50cbd

Please sign in to comment.