Skip to content

Commit 37af742

Browse files
authored
Convert $value and $pattern to string for Str::is(). (#7053)
1 parent 18fc87f commit 37af742

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Str.php

+4
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,17 @@ public static function finish($value, $cap)
364364
*/
365365
public static function is($pattern, $value)
366366
{
367+
$value = (string) $value;
368+
367369
$patterns = Arr::wrap($pattern);
368370

369371
if (empty($patterns)) {
370372
return false;
371373
}
372374

373375
foreach ($patterns as $pattern) {
376+
$pattern = (string) $pattern;
377+
374378
// If the given value is an exact match we can of course return true right
375379
// from the beginning. Otherwise, we will translate asterisks and do an
376380
// actual pattern match against the two strings to see if they match.

tests/StrTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ public function testIsMatch()
333333
$this->assertTrue(Str::isMatch(['/^[a-zA-Z,!]+$/', '/^(.*(.*(.*)))/'], 'Hello, Hyperf!'));
334334
}
335335

336+
public function testIs()
337+
{
338+
$this->assertTrue(Str::is('Hello/*', 'Hello/Hyperf'));
339+
$this->assertFalse(Str::is('Hyperf', 'hyperf'));
340+
$this->assertFalse(Str::is('', 0));
341+
$this->assertFalse(Str::is([null], 0));
342+
$this->assertTrue(Str::is([null], null));
343+
}
344+
336345
public function testCamel()
337346
{
338347
$this->assertSame('helloWorld', Str::camel('HelloWorld'));

0 commit comments

Comments
 (0)