Skip to content

Add tests to filename space separator sanitization#23

Merged
dmsnell merged 1 commit intodmsnell:filenames/avoid-collation-corruptionfrom
sirreal:filenames/avoid-collation-corruption__suggestions
Jul 1, 2025
Merged

Add tests to filename space separator sanitization#23
dmsnell merged 1 commit intodmsnell:filenames/avoid-collation-corruptionfrom
sirreal:filenames/avoid-collation-corruption__suggestions

Conversation

@sirreal
Copy link
Copy Markdown
Collaborator

@sirreal sirreal commented Jul 1, 2025

Add some tests for WordPress#9103.

# from repo checkout
./vendor/bin/phpunit --testdox --group=16330
-OK (1 test, 4 assertions)
+OK (1 test, 7 assertions)

If I revert wp-includes/formatting.php to trunk's version, the tests fail:

_Formatting_Sanitize File Name
 ✘ Replaces spaces
   ┐
   ├ Failed asserting that two strings are identical.
   ┊ ---·Expected
   ┊ +++·Actual
   ┊ @@ @@
   ┊ -'Screenshot-2025-02-19-at-2.17.33-PM.png'
   ┊ +'Screenshot-2025-02-19-at-2.17.33 PM.png'
   │
   ╵ …/tests/phpunit/tests/formatting/sanitizeFileName.php:52
   ┴

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@sirreal sirreal requested a review from dmsnell July 1, 2025 07:56
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 1, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +42 to +48
'unencoded space.png' => 'unencoded-space.png',
'encoded-space.jpg' => 'encoded-space.jpg',
'plus+space.jpg' => 'plusspace.jpg',
'multi %20 +space.png' => 'multi-20-space.png',
"Screenshot 2025-02-19 at 2.17.33\u{202F}PM.png" => 'Screenshot-2025-02-19-at-2.17.33-PM.png',
"Filename with non-breaking\u{00A0}space.txt" => 'Filename-with-non-breaking-space.txt',
"Filename with thin\u{2009}space.txt" => 'Filename-with-thin-space.txt',
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I tried to keep this minimal. Ideally, this would be a data provider but that's best left for a follow-up.

3 different space space characters are handled as expected.

@dmsnell dmsnell merged commit 8ceae7b into dmsnell:filenames/avoid-collation-corruption Jul 1, 2025
12 checks passed
@sirreal sirreal deleted the filenames/avoid-collation-corruption__suggestions branch July 1, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants