contributte / contributte/datagrid
NetteDatabaseDataSource.php - Unhandled date creation in filters
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 296
- Forks
- 215
- PR merge metrics
- No merged PRs in 30d
Description
NetteDatabaseDataSource.php - there is unhandled date creation in filters. It crasches when \DateTime::createFromFormat returns false. It's necessary to check if $date_from and $date_to is false.
`
public function applyFilterDateRange(Filter\FilterDateRange $filter)
{
$conditions = $filter->getCondition();
$value_from = $conditions[$filter->getColumn()]['from'];
$value_to = $conditions[$filter->getColumn()]['to'];
if ($value_from) {
$date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from);
if ($date_from !== false) {
$date_from->setTime(0, 0, 0);
$this->applyWhere("DATE({$filter->getColumn()})", $date_from->format('Y-m-d'), '>=');
}
}
if ($value_to) {
$date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to);
if ($date_to !== false) {
$date_to->setTime(23, 59, 59);
$this->applyWhere("DATE({$filter->getColumn()})", $date_to->format('Y-m-d'), '<=');
}
}
}
`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in NetteDatabaseDataSource.php at applyFilterDateRange and inspect the DateTime::createFromFormat calls for the from and to filter values. Verify the behavior for invalid dates and confirm that valid date ranges still apply their conditions without crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100