Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Validation bypass for 'before' and 'after' rules when paired with 'date_format' rule. #24191

Merged
merged 2 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,12 @@ public function testBeforeAndAfterWithFormat()

$v = new Validator($trans, ['x' => '17:44'], ['x' => 'date_format:H:i|after:17:44']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['x' => '2038-01-18', '2018-05-12' => '2038-01-19'], ['x' => 'date_format:Y-m-d|before:2018-05-12']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['x' => '1970-01-02', '2018-05-12' => '1970-01-01'], ['x' => 'date_format:Y-m-d|after:2018-05-12']);
$this->assertTrue($v->fails());
}

public function testWeakBeforeAndAfter()
Expand Down