Repository navigation
Fonts: Accept TTF uploads detected as font/ttf. #15204
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
07e9b90
Fonts: Accept TTF uploads detected as `font/ttf`.
dhrupo 77a1e42
Merge branch 'trunk' into php86-ttf-font-mime
desrosj c9bc8ec
Fonts: Use a PHP version check for the TTF MIME type.
dhrupo 3d03928
Merge branch 'trunk' into php86-ttf-font-mime
desrosj e2ab4c4
Upload: Accept either MIME type reported for TrueType fonts.
desrosj ce5553d
Tests: Add tests for TrueType font MIME type handling in `wp_check_fi…
desrosj fbb0273
Apply suggestion from @desrosj
desrosj fc19663
Explicitly remove filter at the end of test method.
desrosj 5958f48
Tests: Use tabs to indent the TrueType skip line.
dhrupo a618e1e
Tests: Skip TTF in the multiple font files upload test when it cannot…
desrosj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
| /** | ||
| * Test WP_Font_Utils::get_allowed_font_mime_types(). | ||
| * | ||
| * @package WordPress | ||
| * @subpackage Font Library | ||
| * | ||
| * @group fonts | ||
| * @group font-library | ||
| * | ||
| * @covers WP_Font_Utils::get_allowed_font_mime_types | ||
| */ | ||
| class Tests_Fonts_WpFontUtils_GetAllowedFontMimeTypes extends WP_UnitTestCase { | ||
| /** | ||
| * @ticket 66419 | ||
| * | ||
| * @requires extension fileinfo | ||
| * | ||
| * @dataProvider data_font_file_extensions | ||
| * | ||
| * @param string $extension Font file extension. | ||
| */ | ||
| public function test_should_match_the_mime_type_detected_for_a_font_file( $extension ) { | ||
| if ( 'ttf' === $extension && 'application/octet-stream' === finfo_file( finfo_open( FILEINFO_MIME_TYPE ), DIR_TESTDATA . '/fonts/OpenSans-Regular.ttf' ) ) { | ||
| $this->markTestSkipped( 'This libmagic version cannot detect TrueType fonts. See https://github.com/php/php-src/issues/25051.' ); | ||
| } | ||
|
|
||
| $mimes = WP_Font_Utils::get_allowed_font_mime_types(); | ||
| add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); | ||
|
|
||
| $filetype = wp_check_filetype_and_ext( DIR_TESTDATA . '/fonts/OpenSans-Regular.' . $extension, 'OpenSans-Regular.' . $extension, $mimes ); | ||
|
|
||
| $this->assertSame( $extension, $filetype['ext'], 'The font file extension should be accepted.' ); | ||
| $this->assertSame( $mimes[ $extension ], $filetype['type'], 'The font file mime type should match the allowed mime type.' ); | ||
|
|
||
| remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); | ||
| } | ||
|
desrosj marked this conversation as resolved.
Resolved
|
||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public static function data_font_file_extensions() { | ||
| return array( | ||
| 'otf' => array( 'otf' ), | ||
| 'ttf' => array( 'ttf' ), | ||
| 'woff' => array( 'woff' ), | ||
| 'woff2' => array( 'woff2' ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.