Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated FILTER_SANITIZE_STRING usage. #2768

Merged

Conversation

rawdreeg
Copy link
Contributor

@rawdreeg rawdreeg commented Jul 17, 2024

Changes proposed in this Pull Request:

Remove deprecated FILTER_SANITIZE_STRING usage.

Closes #2588.

str_truncate, str_exists, str_truncate and other related string helper methods in the WooCommerce\Facebook\Framework\Helper class had a fallback for cases where the mbstring PHP extension was not available. This fallback str_to_ascii method would throw a deprecate warning notice because of its use of the FILTER_SANITIZE_STRING constant.

I have considered removing the self::multibyte_loaded() check and falling back on the WP core polyfill. But some mb functions do not have polyfills in the core like mb_strpos. This will require including and loading something like https://github.com/symfony/polyfill-mbstring.

We can look at this when we work on the cleanup task: #2705.

Here, I re-implement str_ascii without filter_var. This keeps printable ASCII chars, stripping out everything from 0-31 and 127-255,.

  • Do the changed files pass phpcs checks? Please remove phpcs:ignore comments in changed files and fix any issues, or delete if not practical.

Screenshots:

Detailed test instructions:

To reproduce:

  1. Ensure your local server has PHP 8.1 or higher.
  2. Enable WP_DEBUG and WP_DEBUG_LOG
  3. Change this line to return false:
    return extension_loaded( 'mbstring' );
  4. Configure Facebook for WooCommerce, notice the deprecation warning notices in your log file

Check out this branch.

You can try to sync a product by editing it; for example, no warning notice should be thrown.

Changelog entry

Fix - Remove deprecated FILTER_SANITIZE_STRING usage.

@rawdreeg rawdreeg self-assigned this Jul 17, 2024
@github-actions github-actions bot added changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug. labels Jul 17, 2024
@rawdreeg rawdreeg requested review from a team and removed request for message-dimke July 17, 2024 13:03
Copy link
Collaborator

@layoutd layoutd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 LGTM thanks @rawdreeg. Test instructions work correctly.

I wasn't very familiar with the functionality so I double-checked the new implementation with some simple test cases and all 🟢

    $test_cases = [
        "Hello World!" => "Hello World!",
        "Hello\x00 World!" => "Hello World!",
        "Hello\x7F World!" => "Hello World!",
        "Hello\x1F World!" => "Hello World!",
        "Hello\x80 World!" => "Hello World!",
        "Hello\nWorld!" => "HelloWorld!", // Newline character removed
    ];

@rawdreeg rawdreeg merged commit e5f4d3b into develop Jul 17, 2024
4 checks passed
@rawdreeg rawdreeg deleted the fix/remove-deprecated-FILTER_SANITIZE_STRING-constant branch July 17, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FILTER_SANITIZE_STRING warning
2 participants