laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.47k stars 419 forks source link

Illuminate\Support\Str::mask position bug #1235

Closed lscar closed 2 years ago

lscar commented 2 years ago

Description:

Illuminate\Support\Str::mask, wrong mask position

This code is not rigorous.Mask error when substring is repeated.

        $start = mb_substr($string, 0, mb_strpos($string, $segment, 0, $encoding), $encoding);
        $end = mb_substr($string, mb_strpos($string, $segment, 0, $encoding) + mb_strlen($segment, $encoding));

Steps To Reproduce:

echo Illuminate\Support\Str::mask('19000000001', '*', 3, 4);

actual output

19****00001

correct output

190****0001
driesvints commented 2 years ago

I don't see an issue here. If you really think there's a bug, feel free to PR the Laravel framework with a fix and test. Thanks

lscar commented 2 years ago

You mean "Illuminate\Support\Str::mask('123412341234', '*', 4, 4)" output "****12341234" is correct, right?

I just want to mask numbers from 5th to 8th.

Am I using it incorrectly?