Skip to content

Commit 108a73f

Browse files
committed
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_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.
1 parent fad7376 commit 108a73f

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

system/Validation/FormatRules.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function alpha_space(?string $value = null): bool
4444
return true;
4545
}
4646

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

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

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

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

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

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

153153
/**
@@ -181,7 +181,7 @@ public function is_natural_no_zero(?string $str = null): bool
181181
*/
182182
public function numeric(?string $str = null): bool
183183
{
184-
return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
184+
return (bool) preg_match('/\A[\-+]?[0-9]*\.?[0-9]+\z/', $str);
185185
}
186186

187187
/**

tests/system/Validation/FormatRulesTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ public function alphaSpaceProvider()
424424
FormatRulesTest::ALPHABET . ' ',
425425
true,
426426
],
427+
[
428+
FormatRulesTest::ALPHABET . "\n",
429+
false,
430+
],
427431
[
428432
FormatRulesTest::ALPHABET . '1',
429433
false,
@@ -506,6 +510,10 @@ public function alphaNumericPunctProvider()
506510
FormatRulesTest::ALPHANUMERIC . '`',
507511
false,
508512
],
513+
[
514+
FormatRulesTest::ALPHANUMERIC . "\n",
515+
false,
516+
],
509517
[
510518
FormatRulesTest::ALPHANUMERIC . '@',
511519
false,
@@ -599,6 +607,10 @@ public function alphaNumericSpaceProvider()
599607
' ' . FormatRulesTest::ALPHANUMERIC . '-',
600608
false,
601609
],
610+
[
611+
' ' . FormatRulesTest::ALPHANUMERIC . "\n",
612+
false,
613+
],
602614
[
603615
null,
604616
false,
@@ -636,6 +648,10 @@ public function alphaDashProvider()
636648
FormatRulesTest::ALPHANUMERIC . '-\ ',
637649
false,
638650
],
651+
[
652+
FormatRulesTest::ALPHANUMERIC . "-\n",
653+
false,
654+
],
639655
[
640656
null,
641657
false,
@@ -722,6 +738,10 @@ public function numericProvider()
722738
'+42',
723739
true,
724740
],
741+
[
742+
"+42\n",
743+
false,
744+
],
725745
[
726746
'123a',
727747
false,
@@ -771,6 +791,10 @@ public function integerProvider()
771791
'-1',
772792
true,
773793
],
794+
[
795+
"+42\n",
796+
false,
797+
],
774798
[
775799
'123a',
776800
false,
@@ -824,6 +848,10 @@ public function decimalProvider()
824848
'0',
825849
true,
826850
],
851+
[
852+
"0\n",
853+
false,
854+
],
827855
[
828856
'1.0a',
829857
false,

0 commit comments

Comments
 (0)