Skip to content

Commit cc237c5

Browse files
authored
Fixed bug that the the validation rule in cannot work for php 8.4 (#7471)
1 parent 3a7fc59 commit cc237c5

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/ValidationRuleParser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ protected static function parseParameters(string $rule, string $parameter): arra
266266
return [$parameter];
267267
}
268268

269-
return str_getcsv($parameter);
269+
if (PHP_VERSION_ID >= 90000) {
270+
return str_getcsv($parameter, escape: '');
271+
}
272+
273+
return str_getcsv($parameter, escape: '\\');
270274
}
271275

272276
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
13+
namespace HyperfTest\Validation\Cases\Stub;
14+
15+
use Hyperf\Validation\ValidationRuleParser;
16+
17+
class ValidationRuleParserStub extends ValidationRuleParser
18+
{
19+
public static function parseParameters(string $rule, string $parameter): array
20+
{
21+
return parent::parseParameters($rule, $parameter);
22+
}
23+
}

tests/Cases/ValidationRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace HyperfTest\Validation\Cases;
1414

1515
use Hyperf\Validation\Rule;
16+
use HyperfTest\Validation\Cases\Stub\ValidationRuleParserStub;
1617
use PHPUnit\Framework\Attributes\CoversNothing;
1718
use PHPUnit\Framework\TestCase;
1819

@@ -32,4 +33,14 @@ public function testMacroable()
3233
$c = Rule::phone();
3334
$this->assertSame('regex:/^([0-9\s\-\+\(\)]*)$/', $c);
3435
}
36+
37+
public function testParseParameters()
38+
{
39+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,4');
40+
$this->assertSame(['1', '2', '3', '4'], $res);
41+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,\4');
42+
$this->assertSame(['1', '2', '3', '\4'], $res);
43+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,\\\4');
44+
$this->assertSame(['1', '2', '3', '\\\4'], $res);
45+
}
3546
}

0 commit comments

Comments
 (0)