firebase / php-jwt

PHP package for JWT
BSD 3-Clause "New" or "Revised" License
9.38k stars 1.27k forks source link

Fix PHP8.2 str_split function returns empty arrays for empty strings #485

Closed HuongNV13 closed 1 year ago

HuongNV13 commented 1 year ago

In PHP 8.2, the str_split function will returns empty arrays for empty strings. See: https://php.watch/versions/8.2/str_split-empty-string-empty-array

We can use mb_str_split() instead

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

bshaffer commented 1 year ago

I'm not sure why exactly, but something is different in mb_str_split that is causing all our tests to fail

HuongNV13 commented 1 year ago

Hi @bshaffer, The failed tests are related to the CLA. I have signed the CLA and rebased the code.

SoulPancake commented 1 year ago

@HuongNV13 CLA has passed but the test suites are still failing as you can see, Can you check once again?

bshaffer commented 1 year ago

The two functions behave differently when dealing with a binary string, which is the case here:

str_split() will split into bytes, rather than characters when dealing with a multi-byte encoded string. Use mb_str_split() to split the string into code points.

If there's a specific error you're trying to prevent, perhaps you can do it by verifying the input beforehand.