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

fix: Bug that can not split correctly when validation rule does not regex_match. #1202

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 6 additions & 4 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,14 @@ protected function splitRules(string $rules): array
$separator = $rules[$open_bracket_pos + 1];

$regex_end_pos = strpos($rules, $separator . ']');
$_rules[] = substr($rules, 0, $regex_end_pos + 2);
if ($regex_end_pos !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move { to next line for consistency

Copy link
Contributor Author

@ytetsuro ytetsuro Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move { to next line for consistency.

comment thanks.
but not need.

$_rules[] = substr($rules, 0, $regex_end_pos + 2);

$rules = substr($rules, $regex_end_pos + 3);
$rules = substr($rules, $regex_end_pos + 3);

$pipe_pos = strpos($rules, '|');
continue;
$pipe_pos = strpos($rules, '|');
continue;
}
}

$_rules[] = substr($rules, 0, $pipe_pos);
Expand Down
25 changes: 25 additions & 0 deletions tests/system/Validation/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,31 @@ public function testHasError()

//--------------------------------------------------------------------

public function testSplitRuleNotRegexMatchTrue()
{
$this->validation->setRules([
'number' => 'greater_than[10]|less_than[12]',
]);
$data = [
'number' => '11',
];

$result = $this->validation->run($data);
$this->assertTrue($result);
}

public function testSplitRuleNotRegexMatchFalse()
{
$this->validation->setRules([
'number' => 'greater_than[10]|less_than[12]',
]);
$data = [
'number' => '16',
];

$result = $this->validation->run($data);
$this->assertFalse($result);
}

public function testSplitRulesTrue()
{
Expand Down