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

Reworked function clean_filename #8

Open
berlindave opened this issue May 16, 2022 · 2 comments
Open

Reworked function clean_filename #8

berlindave opened this issue May 16, 2022 · 2 comments

Comments

@berlindave
Copy link

berlindave commented May 16, 2022

Hello @gesen,

as announced yesterday on the WordPress Plugin support forum, I digged a little deeper into your code. I realized a strange behaviour with a JPG file with German umlauts in the filename, created on a Mac (macOS 10.15.7) – see attached file.

Neither line 469 ($specific_replacements) nor line 472 (remove_accents()) took action regarding the umlauts. The reason probably was a strange character encoding which wasn't recognized.

I did a little research and found a ticket by @Zodiac1978 on the WordPress core trac: https://core.trac.wordpress.org/ticket/30130

I applied the following line: $cleaned_filename = normalizer_normalize( $cleaned_filename, Normalizer::FORM_C );
… and the problem was solved. I could even get rid of your "$specific_replacements" because the WordPress function remove_accents() was doing the job.

I made a little Gist with the reworked function:
https://gist.github.com/berlindave/7df153e4196b2144e5fc268b3f0ce6b1

I hope this could help solving some problems.

Best regards
David

Süße, sämige Flöten.jpg.zip

@Zodiac1978
Copy link

Zodiac1978 commented May 16, 2022

Unfortunately the needed intl extension is not always available, although it is recommended by the hosting team to use it:
https://make.wordpress.org/hosting/2021/05/20/why-hosters-should-install-the-php-intl-extension/

There is another ticket, especially for the remove_accents() case:
https://core.trac.wordpress.org/ticket/35951

https://core.trac.wordpress.org/ticket/22363 fixed many things in WordPress 5.5, but the NFD/NFC case is still there.

Besides the mentioned ticket there is this sort of duplicate which contains more discussions and solutions:
https://core.trac.wordpress.org/ticket/24661

The code in the gist should be checking if the function exists like the patch in one of the mentioned tickets it does, to prevent warning in the logs.

All the best
Torsten

@berlindave
Copy link
Author

berlindave commented May 16, 2022

Thank you again, @Zodiac1978, for these helpful hints!
I updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants