Skip to content

Commit

Permalink
Fix validation bypass for rules 'before' and 'after' when paired with…
Browse files Browse the repository at this point in the history
… 'date_format'.

Now when when there is both a 'date_format' rule and a 'before' and/or 'after' rule,
the first parameter will be converted to a timestamp, and only if that fails, it will
be considered as a name for another field. This exactly the same behavior when there
isn't a date_format rule.

fixes #24191
  • Loading branch information
jonnsl committed May 15, 2018
1 parent 8ba7879 commit 3ce7ca5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ protected function compareDates($attribute, $value, $parameters, $operator)
}

if ($format = $this->getDateFormat($attribute)) {
return $this->checkDateTimeOrder(
$format, $value, $this->getValue($parameters[0]) ?: $parameters[0], $operator
);
return $this->checkDateTimeOrder($format, $value, $parameters[0], $operator);
}

if (! $date = $this->getDateTimestamp($parameters[0])) {
Expand Down Expand Up @@ -194,11 +192,13 @@ protected function getDateTimestamp($value)
*/
protected function checkDateTimeOrder($format, $first, $second, $operator)
{
$first = $this->getDateTimeWithOptionalFormat($format, $first);
$firstDate = $this->getDateTimeWithOptionalFormat($format, $first);

$second = $this->getDateTimeWithOptionalFormat($format, $second);
if (! $secondDate = $this->getDateTimeWithOptionalFormat($format, $second)) {
$secondDate = $this->getDateTimeWithOptionalFormat($format, $this->getValue($second));
}

return ($first && $second) && ($this->compare($first, $second, $operator));
return ($firstDate && $secondDate) && ($this->compare($firstDate, $secondDate, $operator));
}

/**
Expand Down

0 comments on commit 3ce7ca5

Please sign in to comment.