wordpress-develop/tests/phpunit/data
Tonya Mork 8aa625b795 Media: Fix TypeError and improve wp_exif_frac2dec() to only return int or float.
For certain images, `wp_exif_frac2dec()` unexpectedly returned a string instead of `int` or `float`. This can occur when an image is missing meta and calls the function with `'0/0'`. For those images, a fatal error was thrown on PHP 8.0+:

{{{
TypeError: round(): Argument #1 ($num) must be of type int|float, string given
}}}

Upon deeper review, inconsistent and unexpected results were returned from different types of input values passed to the function.

Changes are:

* Maintains backwards-compatibility for valid input values.
* Fixes handling of invalid input values by bailing out to return the documented type of `int|float` by returning `0`.
* Improves the fractional conditional check.
* Improves the calculated fraction handling to ensure (a) the numerator and denominator are both numeric and (b) the denominator is not equal to zero.
* Safeguards the behavior via tests for all possible ways code could flow through the function.
* Safeguards the backwards-compatibility of the `wp_read_image_metadata()` by adding some defensive coding around the calls to the `wp_exif_frac2dec()` function.

These changes fix the fatal error and make the function more secure, stable, and predictable while maintaining backwards-compatibility for valid input values.

Follow-up to [6313], [9119], [22319], [28367], [45611], [47287].

Props adamsilverstein, jrf, peterwilsoncc, praem90, stevegs, tobiasbg.
Fixes #54385.

git-svn-id: https://develop.svn.wordpress.org/trunk@52269 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-29 19:34:51 +00:00
..
blocks Blocks: Add support for variations in block.json` file 2021-08-11 09:06:31 +00:00
export Ensure svn:eol-style is consistently set for all files (part 2). 2019-10-25 19:27:49 +00:00
feed Feed: Merge multiple header values to avoid fatal error. 2020-12-16 00:49:32 +00:00
formatting Themes: Make sure get_file_data() recognizes headers prefixed by <?php tag. 2021-06-18 14:02:44 +00:00
functions Tests: Some test improvements for clean_dirsize_cache() tests: 2021-10-26 02:02:50 +00:00
images Media: Fix TypeError and improve wp_exif_frac2dec() to only return int or float. 2021-11-29 19:34:51 +00:00
languages Fix: Update block-theme-pl_PL.mo file. 2021-11-08 20:32:39 +00:00
plugins I18N: Revert [49236] for now to investigate alternative implementations. 2020-11-12 14:41:19 +00:00
pomo Move PHPUnit tests into a tests/phpunit directory. 2013-08-29 18:39:34 +00:00
templates Editor: Add block theme infrastructure 2021-11-08 23:09:53 +00:00
theme-file-child Themes: Improve child theme file inheritance by introducing functions for locating and fetching the URL or path to files within child and parent themes. 2016-09-08 22:53:57 +00:00
theme-file-parent Themes: Improve child theme file inheritance by introducing functions for locating and fetching the URL or path to files within child and parent themes. 2016-09-08 22:53:57 +00:00
themedir1 Themes: Update the base folders for templates and template parts in block themes. 2021-11-25 10:57:19 +00:00
uploads Ensure svn:eol-style is consistently set for all files (part 2). 2019-10-25 19:27:49 +00:00
widgets Widgets: Make sure WP_Widget constructor creates a correct id_base value for a namespaced widget class. 2021-05-23 08:50:44 +00:00
WPHTTP-testcase-redirection-script.php Docs: Improve inline comments per the documentation standards. 2020-01-29 00:43:23 +00:00