From 07e9b909f90b3ceb9c4bfaa97272373882fca0b0 Mon Sep 17 00:00:00 2001 From: Dhrupo Nil Date: Fri, 30 Oct 2026 14:26:28 +0600 Subject: [PATCH 1/8] Fonts: Accept TTF uploads detected as `font/ttf`. libmagic detects TrueType fonts as `font/ttf` since file 5.47, while `WP_Font_Utils::get_allowed_font_mime_types()` expects `font/sfnt`. PHP 8.6 bundles libmagic 5.48, and builds that link the system libmagic can use a newer one on older PHP versions, so TTF uploads to the Font Library were rejected. During font uploads, a `.ttf` file detected as either `font/sfnt` or `font/ttf` is now accepted. Props dhrupo. Fixes #66419. --- src/wp-includes/fonts/class-wp-font-utils.php | 36 ++++++++ .../class-wp-rest-font-faces-controller.php | 2 + .../wpFontUtils/allowTtfMimeTypes.php | 92 +++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php diff --git a/src/wp-includes/fonts/class-wp-font-utils.php b/src/wp-includes/fonts/class-wp-font-utils.php index ee175f66aab6d..28b73fc228753 100644 --- a/src/wp-includes/fonts/class-wp-font-utils.php +++ b/src/wp-includes/fonts/class-wp-font-utils.php @@ -254,4 +254,40 @@ public static function get_allowed_font_mime_types() { 'woff2' => PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2', ); } + + /** + * Accepts a TTF font file whose detected mime type is either TrueType mime type. + * + * libmagic detects TrueType fonts as font/ttf since version 5.47 and as font/sfnt before, + * and PHP may use either the bundled or the system library. + * + * @since 7.2.0 + * + * @access private + * + * @param array $data { + * Values for the extension, mime type, and corrected filename. + * + * @type string|false $ext File extension, or false if the file doesn't match a mime type. + * @type string|false $type File mime type, or false if the file doesn't match a mime type. + * @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined. + * } + * @param string $file Full path to the file. + * @param string $filename The name of the file. + * @param string[] $mimes Array of mime types keyed by their file extension regex. + * @param string|false $real_mime The actual mime type or false if the type cannot be determined. + * @return array The file data, with the TTF extension and mime type when accepted. + */ + public static function allow_ttf_mime_types( $data, $file, $filename, $mimes, $real_mime ) { + if ( + ! $data['type'] + && in_array( $real_mime, array( 'font/sfnt', 'font/ttf' ), true ) + && 'ttf' === strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ) + ) { + $data['ext'] = 'ttf'; + $data['type'] = $real_mime; + } + + return $data; + } } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php index 2aaf63cd1058f..9df25fda3994c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php @@ -866,6 +866,7 @@ protected function sanitize_src( $value ) { */ protected function handle_font_file_upload( $file ) { add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); + add_filter( 'wp_check_filetype_and_ext', array( 'WP_Font_Utils', 'allow_ttf_mime_types' ), 10, 5 ); // Filter the upload directory to return the fonts directory. add_filter( 'upload_dir', '_wp_filter_font_directory' ); @@ -885,6 +886,7 @@ protected function handle_font_file_upload( $file ) { $uploaded_file = wp_handle_upload( $file, $overrides ); remove_filter( 'upload_dir', '_wp_filter_font_directory' ); + remove_filter( 'wp_check_filetype_and_ext', array( 'WP_Font_Utils', 'allow_ttf_mime_types' ) ); remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); return $uploaded_file; diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php new file mode 100644 index 0000000000000..554b395db4dcd --- /dev/null +++ b/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php @@ -0,0 +1,92 @@ + false, + 'type' => false, + 'proper_filename' => false, + ); + + $data = WP_Font_Utils::allow_ttf_mime_types( $rejected, '/tmp/font.ttf', 'OpenSans-Regular.ttf', WP_Font_Utils::get_allowed_font_mime_types(), $real_mime ); + + $this->assertSame( 'ttf', $data['ext'] ); + $this->assertSame( $real_mime, $data['type'] ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_ttf_mime_types() { + return array( + 'libmagic before 5.47' => array( 'font/sfnt' ), + 'libmagic 5.47 and up' => array( 'font/ttf' ), + ); + } + + /** + * @ticket 66419 + * + * @dataProvider data_should_not_accept + * + * @param string $filename Uploaded file name. + * @param string|false $real_mime MIME type detected by fileinfo. + */ + public function test_should_not_accept_other_files( $filename, $real_mime ) { + $rejected = array( + 'ext' => false, + 'type' => false, + 'proper_filename' => false, + ); + + $data = WP_Font_Utils::allow_ttf_mime_types( $rejected, '/tmp/file', $filename, WP_Font_Utils::get_allowed_font_mime_types(), $real_mime ); + + $this->assertSame( $rejected, $data ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_not_accept() { + return array( + 'ttf detected as a generic binary' => array( 'OpenSans-Regular.ttf', 'application/octet-stream' ), + 'ttf not detected' => array( 'OpenSans-Regular.ttf', false ), + 'truetype content in a php file' => array( 'shell.php', 'font/ttf' ), + 'truetype content in an otf file' => array( 'OpenSans-Regular.otf', 'font/ttf' ), + ); + } + + /** + * @ticket 66419 + */ + public function test_should_keep_an_already_accepted_file() { + $accepted = array( + 'ext' => 'ttf', + 'type' => 'font/sfnt', + 'proper_filename' => false, + ); + + $this->assertSame( $accepted, WP_Font_Utils::allow_ttf_mime_types( $accepted, '/tmp/font.ttf', 'OpenSans-Regular.ttf', WP_Font_Utils::get_allowed_font_mime_types(), 'font/sfnt' ) ); + } +} From c9bc8ec86b6dc39517ff1c7e437305982e7db3c9 Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Wed, 4 Nov 2026 23:11:03 +0600 Subject: [PATCH 2/8] Fonts: Use a PHP version check for the TTF MIME type. Replace the `wp_check_filetype_and_ext` callback with a `PHP_VERSION_ID` check in `WP_Font_Utils::get_allowed_font_mime_types()`, matching the existing WOFF and WOFF2 entries. PHP 8.6 bundles a libmagic that reports TrueType fonts as `font/ttf` instead of `font/sfnt`. Add a test that checks the detected MIME type of each test font file against the allowed font MIME types. See #66419. --- src/wp-includes/fonts/class-wp-font-utils.php | 38 +------- .../class-wp-rest-font-faces-controller.php | 2 - .../wpFontUtils/allowTtfMimeTypes.php | 92 ------------------- .../wpFontUtils/getAllowedFontMimeTypes.php | 46 ++++++++++ 4 files changed, 47 insertions(+), 131 deletions(-) delete mode 100644 tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php create mode 100644 tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php diff --git a/src/wp-includes/fonts/class-wp-font-utils.php b/src/wp-includes/fonts/class-wp-font-utils.php index 28b73fc228753..7eb639fa9151e 100644 --- a/src/wp-includes/fonts/class-wp-font-utils.php +++ b/src/wp-includes/fonts/class-wp-font-utils.php @@ -249,45 +249,9 @@ private static function apply_sanitizer( $value, $sanitizer ) { public static function get_allowed_font_mime_types() { return array( 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'font/sfnt', + 'ttf' => PHP_VERSION_ID >= 80600 ? 'font/ttf' : 'font/sfnt', 'woff' => PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff', 'woff2' => PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2', ); } - - /** - * Accepts a TTF font file whose detected mime type is either TrueType mime type. - * - * libmagic detects TrueType fonts as font/ttf since version 5.47 and as font/sfnt before, - * and PHP may use either the bundled or the system library. - * - * @since 7.2.0 - * - * @access private - * - * @param array $data { - * Values for the extension, mime type, and corrected filename. - * - * @type string|false $ext File extension, or false if the file doesn't match a mime type. - * @type string|false $type File mime type, or false if the file doesn't match a mime type. - * @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined. - * } - * @param string $file Full path to the file. - * @param string $filename The name of the file. - * @param string[] $mimes Array of mime types keyed by their file extension regex. - * @param string|false $real_mime The actual mime type or false if the type cannot be determined. - * @return array The file data, with the TTF extension and mime type when accepted. - */ - public static function allow_ttf_mime_types( $data, $file, $filename, $mimes, $real_mime ) { - if ( - ! $data['type'] - && in_array( $real_mime, array( 'font/sfnt', 'font/ttf' ), true ) - && 'ttf' === strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ) - ) { - $data['ext'] = 'ttf'; - $data['type'] = $real_mime; - } - - return $data; - } } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php index 9df25fda3994c..2aaf63cd1058f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php @@ -866,7 +866,6 @@ protected function sanitize_src( $value ) { */ protected function handle_font_file_upload( $file ) { add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); - add_filter( 'wp_check_filetype_and_ext', array( 'WP_Font_Utils', 'allow_ttf_mime_types' ), 10, 5 ); // Filter the upload directory to return the fonts directory. add_filter( 'upload_dir', '_wp_filter_font_directory' ); @@ -886,7 +885,6 @@ protected function handle_font_file_upload( $file ) { $uploaded_file = wp_handle_upload( $file, $overrides ); remove_filter( 'upload_dir', '_wp_filter_font_directory' ); - remove_filter( 'wp_check_filetype_and_ext', array( 'WP_Font_Utils', 'allow_ttf_mime_types' ) ); remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); return $uploaded_file; diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php deleted file mode 100644 index 554b395db4dcd..0000000000000 --- a/tests/phpunit/tests/fonts/font-library/wpFontUtils/allowTtfMimeTypes.php +++ /dev/null @@ -1,92 +0,0 @@ - false, - 'type' => false, - 'proper_filename' => false, - ); - - $data = WP_Font_Utils::allow_ttf_mime_types( $rejected, '/tmp/font.ttf', 'OpenSans-Regular.ttf', WP_Font_Utils::get_allowed_font_mime_types(), $real_mime ); - - $this->assertSame( 'ttf', $data['ext'] ); - $this->assertSame( $real_mime, $data['type'] ); - } - - /** - * Data provider. - * - * @return array[] - */ - public function data_ttf_mime_types() { - return array( - 'libmagic before 5.47' => array( 'font/sfnt' ), - 'libmagic 5.47 and up' => array( 'font/ttf' ), - ); - } - - /** - * @ticket 66419 - * - * @dataProvider data_should_not_accept - * - * @param string $filename Uploaded file name. - * @param string|false $real_mime MIME type detected by fileinfo. - */ - public function test_should_not_accept_other_files( $filename, $real_mime ) { - $rejected = array( - 'ext' => false, - 'type' => false, - 'proper_filename' => false, - ); - - $data = WP_Font_Utils::allow_ttf_mime_types( $rejected, '/tmp/file', $filename, WP_Font_Utils::get_allowed_font_mime_types(), $real_mime ); - - $this->assertSame( $rejected, $data ); - } - - /** - * Data provider. - * - * @return array[] - */ - public function data_should_not_accept() { - return array( - 'ttf detected as a generic binary' => array( 'OpenSans-Regular.ttf', 'application/octet-stream' ), - 'ttf not detected' => array( 'OpenSans-Regular.ttf', false ), - 'truetype content in a php file' => array( 'shell.php', 'font/ttf' ), - 'truetype content in an otf file' => array( 'OpenSans-Regular.otf', 'font/ttf' ), - ); - } - - /** - * @ticket 66419 - */ - public function test_should_keep_an_already_accepted_file() { - $accepted = array( - 'ext' => 'ttf', - 'type' => 'font/sfnt', - 'proper_filename' => false, - ); - - $this->assertSame( $accepted, WP_Font_Utils::allow_ttf_mime_types( $accepted, '/tmp/font.ttf', 'OpenSans-Regular.ttf', WP_Font_Utils::get_allowed_font_mime_types(), 'font/sfnt' ) ); - } -} diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php new file mode 100644 index 0000000000000..7e46e181d845f --- /dev/null +++ b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php @@ -0,0 +1,46 @@ +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.' ); + } + + /** + * 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' ), + ); + } +} From e2ab4c43bdb8774a7a993de84816b19ed1f6c8ff Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:21:14 -0500 Subject: [PATCH 3/8] Upload: Accept either MIME type reported for TrueType fonts. libmagic 5.47 changed the MIME type reported for TrueType fonts from `font/sfnt` to the canonical `font/ttf`. The libmagic bundled with PHP 8.6 includes this change, but PHP builds that use the system libmagic can report either type regardless of the PHP version. `wp_check_filetype_and_ext()` now accepts either type when the file's contents are detected as a TrueType font, and `WP_Font_Utils::get_allowed_font_mime_types()` returns `font/ttf` for TTF files on all PHP versions instead of switching on `PHP_VERSION_ID`. See #66419. Co-Authored-By: Claude Opus 5.5 --- src/wp-includes/fonts/class-wp-font-utils.php | 13 +++++++++---- src/wp-includes/functions.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/fonts/class-wp-font-utils.php b/src/wp-includes/fonts/class-wp-font-utils.php index 7eb639fa9151e..57385ff8084ed 100644 --- a/src/wp-includes/fonts/class-wp-font-utils.php +++ b/src/wp-includes/fonts/class-wp-font-utils.php @@ -236,11 +236,16 @@ private static function apply_sanitizer( $value, $sanitizer ) { /** * Returns the expected mime-type values for font files, depending on PHP version. * - * This is needed because font mime types vary by PHP version, so checking the PHP version - * is necessary until a list of valid mime-types for each file extension can be provided to - * the 'upload_mimes' filter. + * This is needed because the mime types detected for WOFF and WOFF2 files vary by PHP version, + * so checking the PHP version is necessary until a list of valid mime-types for each file + * extension can be provided to the 'upload_mimes' filter. + * + * TrueType fonts can be detected as either font/ttf or font/sfnt depending on the libmagic + * version, and both are accepted by wp_check_filetype_and_ext(). The canonical font/ttf + * is returned for them on all PHP versions. * * @since 6.5.0 + * @since 7.2.0 TrueType fonts now use the font/ttf mime type on all PHP versions. * * @access private * @@ -249,7 +254,7 @@ private static function apply_sanitizer( $value, $sanitizer ) { public static function get_allowed_font_mime_types() { return array( 'otf' => 'application/vnd.ms-opentype', - 'ttf' => PHP_VERSION_ID >= 80600 ? 'font/ttf' : 'font/sfnt', + 'ttf' => 'font/ttf', 'woff' => PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff', 'woff2' => PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2', ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index eac938b2c4d1a..f31c53aa7dd4f 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3357,6 +3357,19 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $type = false; $ext = false; } + } elseif ( in_array( $real_mime, array( 'font/ttf', 'font/sfnt' ), true ) ) { + /* + * libmagic 5.47 changed the type reported for TrueType fonts from font/sfnt to the + * canonical font/ttf. PHP 8.6 bundles a libmagic version with this change, but PHP + * builds that use the system libmagic can report either type, so both are accepted + * for TrueType fonts. + * + * @link https://github.com/file/file/commit/6481672a8eb64c2758bf6429d9a76ee5a22174e9 + */ + if ( ! in_array( $type, array( 'font/ttf', 'font/sfnt' ), true ) ) { + $type = false; + $ext = false; + } } else { if ( $type !== $real_mime ) { /* From ce5553deb2d7d62cea11c91b257ef1daff5f7620 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:25:10 -0500 Subject: [PATCH 4/8] Tests: Add tests for TrueType font MIME type handling in `wp_check_filetype_and_ext()`. Tests that a TrueType font is accepted whether `font/ttf` or `font/sfnt` is expected. Whichever type the local libmagic reports, one of the two cases expects the other, so the handling for both types is exercised on every PHP version. The test is skipped when libmagic reports something else for TrueType fonts, as it does on PHP 8.6.0 builds affected by https://github.com/php/php-src/issues/25051. Also tests that a font of another format named with a `.ttf` extension is still rejected. See #66419. Co-Authored-By: Claude Opus 5.5 --- tests/phpunit/tests/functions.php | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 64d84458c334f..8ba133e930ad0 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1861,6 +1861,91 @@ static function ( $mimes ) use ( $woff_mime_type ) { $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); } + /** + * Tests that TrueType fonts are accepted whether font/ttf or font/sfnt is expected. + * + * libmagic 5.47 changed the type reported for TrueType fonts from font/sfnt to font/ttf. + * Expecting each type in turn ensures that whichever one libmagic reports, a file is also + * accepted when the other is expected. + * + * @ticket 66419 + * @group ms-excluded + * @requires extension fileinfo + * + * @dataProvider data_wp_check_filetype_and_ext_with_ttf_mime_types + * + * @covers ::wp_check_filetype_and_ext + * + * @param string $mime_type The mime type expected for TTF files. + */ + public function test_wp_check_filetype_and_ext_accepts_either_ttf_mime_type( $mime_type ) { + $file = DIR_TESTDATA . '/fonts/OpenSans-Regular.ttf'; + $filename = 'OpenSans-Regular.ttf'; + + $detected_type = finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $file ); + if ( ! in_array( $detected_type, array( 'font/ttf', 'font/sfnt' ), true ) ) { + $this->markTestSkipped( "This version of libmagic detects TrueType fonts as {$detected_type}." ); + } + + $filter = static function ( $mimes ) use ( $mime_type ) { + $mimes['ttf'] = $mime_type; + return $mimes; + }; + add_filter( 'upload_mimes', $filter ); + + $expected = array( + 'ext' => 'ttf', + 'type' => $mime_type, + 'proper_filename' => false, + ); + + $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); + + remove_filter( 'upload_mimes', $filter ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_wp_check_filetype_and_ext_with_ttf_mime_types() { + return array( + 'font/ttf' => array( 'font/ttf' ), + 'font/sfnt' => array( 'font/sfnt' ), + ); + } + + /** + * Tests that a font file of another format is rejected when named with a .ttf extension. + * + * @ticket 66419 + * @group ms-excluded + * @requires extension fileinfo + * + * @covers ::wp_check_filetype_and_ext + */ + public function test_wp_check_filetype_and_ext_rejects_other_font_formats_as_ttf() { + $file = DIR_TESTDATA . '/fonts/OpenSans-Regular.woff'; + $filename = 'OpenSans-Regular.ttf'; + + $filter = static function ( $mimes ) { + $mimes['ttf'] = 'font/ttf'; + return $mimes; + }; + add_filter( 'upload_mimes', $filter ); + + $expected = array( + 'ext' => false, + 'type' => false, + 'proper_filename' => false, + ); + + $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); + + remove_filter( 'upload_mimes', $filter ); + } + /** * Test file path validation * From fbb027392e8c047ff7a02cf76931e60a0ea13bf8 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:11:43 -0500 Subject: [PATCH 5/8] Apply suggestion from @desrosj Temporarily skip the new test for `ttf` files when the upstream bug is still present. --- .../font-library/wpFontUtils/getAllowedFontMimeTypes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php index 7e46e181d845f..acee0f9f76725 100644 --- a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php +++ b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php @@ -21,6 +21,10 @@ class Tests_Fonts_WpFontUtils_GetAllowedFontMimeTypes extends WP_UnitTestCase { * @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' ) ); From fc19663af9acc51914372b0ec678548697571512 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:12:02 -0500 Subject: [PATCH 6/8] Explicitly remove filter at the end of test method. --- .../fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php index acee0f9f76725..4ed12d71eb611 100644 --- a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php +++ b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php @@ -32,6 +32,8 @@ public function test_should_match_the_mime_type_detected_for_a_font_file( $exten $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' ) ); } /** From 5958f48be561f2639d0ddb255aa1a779f15bc6b1 Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Sat, 7 Nov 2026 00:27:29 +0600 Subject: [PATCH 7/8] Tests: Use tabs to indent the TrueType skip line. --- .../fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php index 4ed12d71eb611..80c2de8a4e176 100644 --- a/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php +++ b/tests/phpunit/tests/fonts/font-library/wpFontUtils/getAllowedFontMimeTypes.php @@ -22,7 +22,7 @@ class Tests_Fonts_WpFontUtils_GetAllowedFontMimeTypes extends WP_UnitTestCase { */ 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.' ); + $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(); From a618e1e03c1f8c40fbc9cd5fc0490eaaa3deebb0 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:54:02 -0500 Subject: [PATCH 8/8] Tests: Skip TTF in the multiple font files upload test when it cannot be detected. Some libmagic versions, such as the one bundled with PHP 8.6, cannot detect TrueType fonts and report them as `application/octet-stream`. This causes the TTF file to be rejected and the whole request in `test_create_item_with_multiple_font_files()` to fail with a 400. The TTF file is now left out of the upload when it cannot be detected, so the remaining formats are still tested. See https://github.com/php/php-src/issues/25051. Co-Authored-By: Claude Opus 5.5 --- .../font-library/wpRestFontFacesController.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php index 05af011f5cf0a..2a2026ccf2458 100644 --- a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php +++ b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php @@ -463,7 +463,20 @@ function ( $font_dir ) { */ public function test_create_item_with_multiple_font_files() { wp_set_current_user( self::$admin_id ); - $files = $this->setup_font_file_upload( array( 'ttf', 'otf', 'woff', 'woff2' ) ); + + $formats = array( 'ttf', 'otf', 'woff', 'woff2' ); + + /* + * Some libmagic versions cannot detect TrueType fonts and report them as + * application/octet-stream, which causes the upload to be rejected. + * + * @link https://github.com/php/php-src/issues/25051 + */ + if ( 'application/octet-stream' === finfo_file( finfo_open( FILEINFO_MIME_TYPE ), DIR_TESTDATA . '/fonts/OpenSans-Regular.ttf' ) ) { + $formats = array_diff( $formats, array( 'ttf' ) ); + } + + $files = $this->setup_font_file_upload( $formats ); $request = new WP_REST_Request( 'POST', '/wp/v2/font-families/' . self::$font_family_id . '/font-faces' ); $request->set_param( 'theme_json_version', WP_REST_Font_Faces_Controller::LATEST_THEME_JSON_VERSION_SUPPORTED ); @@ -488,7 +501,7 @@ public function test_create_item_with_multiple_font_files() { $this->check_file_meta( $data['id'], $data['font_face_settings']['src'] ); $settings = $data['font_face_settings']; - $this->assertCount( 4, $settings['src'], 'There should be 4 items in the font_face_settings::src data.' ); + $this->assertCount( count( $files ), $settings['src'], 'There should be one item in the font_face_settings::src data for each uploaded file.' ); } /**