Skip to content

Commit

Permalink
fix: treated as false if there is a newline at the end.
Browse files Browse the repository at this point in the history
test: Add a test case where the last string is a newline code when alpha_numeric_punct rule.

fix: treated as false if there is a newline at the end.

test: Add a test case where the last string is a newline code when alpha_numeric_space rule.

fix: treated as false if there is a newline at the end.

test: Add a test case where the last string is a newline code when decimal rule.

fix: treated as false if there is a newline at the end.

fix: treated as false if there is a newline at the end for alpha_numeric_space.

test: Add a test case where the last string is a newline code when numeric rule.

fix: treated as false if there is a newline at the end for numeric rule.

test: Add a test case where the last string is a newline code when decimal rule.

fix: treated as false if there is a newline at the end for alpha_dash rule.

test: Add a test case where the last string is a newline code when integer rule.

fix: treated as false if there is a newline at the end for integer rule.

fix: typo.
  • Loading branch information
ytetsuro committed Jan 11, 2021
1 parent fad7376 commit 108a73f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
14 changes: 7 additions & 7 deletions system/Validation/FormatRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function alpha_space(?string $value = null): bool
return true;
}

return (bool) preg_match('/^[A-Z ]+$/i', $value);
return (bool) preg_match('/\A[A-Z ]+\z/i', $value);
}

/**
Expand All @@ -56,7 +56,7 @@ public function alpha_space(?string $value = null): bool
*/
public function alpha_dash(?string $str = null): bool
{
return (bool) preg_match('/^[a-z0-9_-]+$/i', $str);
return (bool) preg_match('/\A[a-z0-9_-]+\z/i', $str);
}

/**
Expand All @@ -72,7 +72,7 @@ public function alpha_dash(?string $str = null): bool
*/
public function alpha_numeric_punct($str)
{
return (bool) preg_match('/^[A-Z0-9 ~!#$%\&\*\-_+=|:.]+$/i', $str);
return (bool) preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str);
}

/**
Expand All @@ -96,7 +96,7 @@ public function alpha_numeric(?string $str = null): bool
*/
public function alpha_numeric_space(?string $str = null): bool
{
return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str);
return (bool) preg_match('/\A[A-Z0-9 ]+\z/i', $str);
}

/**
Expand All @@ -123,7 +123,7 @@ public function string($str = null): bool
*/
public function decimal(?string $str = null): bool
{
return (bool) preg_match('/^[-+]?[0-9]{0,}\.?[0-9]+$/', $str);
return (bool) preg_match('/\A[-+]?[0-9]{0,}\.?[0-9]+\z/', $str);
}

/**
Expand All @@ -147,7 +147,7 @@ public function hex(?string $str = null): bool
*/
public function integer(?string $str = null): bool
{
return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
return (bool) preg_match('/\A[\-+]?[0-9]+\z/', $str);
}

/**
Expand Down Expand Up @@ -181,7 +181,7 @@ public function is_natural_no_zero(?string $str = null): bool
*/
public function numeric(?string $str = null): bool
{
return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
return (bool) preg_match('/\A[\-+]?[0-9]*\.?[0-9]+\z/', $str);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/system/Validation/FormatRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ public function alphaSpaceProvider()
FormatRulesTest::ALPHABET . ' ',
true,
],
[
FormatRulesTest::ALPHABET . "\n",
false,
],
[
FormatRulesTest::ALPHABET . '1',
false,
Expand Down Expand Up @@ -506,6 +510,10 @@ public function alphaNumericPunctProvider()
FormatRulesTest::ALPHANUMERIC . '`',
false,
],
[
FormatRulesTest::ALPHANUMERIC . "\n",
false,
],
[
FormatRulesTest::ALPHANUMERIC . '@',
false,
Expand Down Expand Up @@ -599,6 +607,10 @@ public function alphaNumericSpaceProvider()
' ' . FormatRulesTest::ALPHANUMERIC . '-',
false,
],
[
' ' . FormatRulesTest::ALPHANUMERIC . "\n",
false,
],
[
null,
false,
Expand Down Expand Up @@ -636,6 +648,10 @@ public function alphaDashProvider()
FormatRulesTest::ALPHANUMERIC . '-\ ',
false,
],
[
FormatRulesTest::ALPHANUMERIC . "-\n",
false,
],
[
null,
false,
Expand Down Expand Up @@ -722,6 +738,10 @@ public function numericProvider()
'+42',
true,
],
[
"+42\n",
false,
],
[
'123a',
false,
Expand Down Expand Up @@ -771,6 +791,10 @@ public function integerProvider()
'-1',
true,
],
[
"+42\n",
false,
],
[
'123a',
false,
Expand Down Expand Up @@ -824,6 +848,10 @@ public function decimalProvider()
'0',
true,
],
[
"0\n",
false,
],
[
'1.0a',
false,
Expand Down

0 comments on commit 108a73f

Please sign in to comment.