-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Font Library: sanitize font collection data #58636
Conversation
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 Core SVNIf you're a Core Committer, use this list when committing to
GitHub Merge commitsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php ❔ lib/compat/wordpress-6.5/fonts/class-wp-font-utils.php ❔ phpunit/tests/fonts/font-library/wpFontCollection/__construct.php ❔ phpunit/tests/fonts/font-library/wpFontCollection/getData.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php |
…ys sanitized following the font collection schema
95389bf
to
a581183
Compare
- Sanitize and validate as early as possible, so that appropriate notices are logged right away - Use static method for sanitization schema so that we can use a closure rather than a public method for src sanitization - Adds a check for WP_Font_Utils::sanitize_from_schema so that class callables like array( $this, 'sanitization_method' ) can be used - Updates method name to indicate that sanitization is done first, as this might remove invalid data and affect the validation result
a581183
to
f307972
Compare
@matiasbenedetto I made an attempt to streamline this and pushed a commit to this branch:
Feel free to revert if you don't agree with the changes. Otherwise I think this now looks ready to go. |
@@ -158,7 +158,7 @@ public static function sanitize_from_schema( $tree, $schema ) { | |||
} | |||
|
|||
$is_value_array = is_array( $value ); | |||
$is_schema_array = is_array( $schema[ $key ] ); | |||
$is_schema_array = is_array( $schema[ $key ] ) && ! is_callable( $schema[ $key ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this check allows using a class instance method, like array( $this, 'sanitization_method' )
.
What?
Font Library: sanitize font collection data.
get_data
is always sanitized.Why?
To return just the data that's safe to return.
How?
Testing Instructions
Run this PHP snippet featuring a font collection with risky data:
Request that font collection using the API:
the response should be: