XjSv / Cooked

A recipe plugin for WordPress.
https://wordpress.org/plugins/cooked/
GNU General Public License v3.0
3 stars 3 forks source link

Validating malformed Amount values #35

Closed gkv-ckultzow closed 2 months ago

gkv-ckultzow commented 2 months ago

Ran into an example where an amount had been ham-handed as 1 /12 instead of 1 1/2 This created a critical PHP error, feels like there's an opportunity to make that fail softer (either force convert to 1/12 and that's on QA to catch, or validating as malformed prior to save attempt)

`PHP Fatal error: Uncaught NXP\Exception\IncorrectExpression Exception in /plugins/cooked/vendor/nxp/math-executor/src/NXP/Classes/Operator.php:44 Stack trace:

0 /plugins/cooked/vendor/nxp/math-executor/src/NXP/Classes/Calculator.php(82): NXP\Classes\Operator->execute(Array)

1 /plugins/cooked/vendor/nxp/math-executor/src/NXP/MathExecutor.php(110): NXP\Classes\Calculator->calculate(Array, Array, NULL)

2 /plugins/cooked/includes/class.cooked-measurements.php(470): NXP\MathExecutor->execute('/12')

3 /plugins/cooked/includes/class.cooked-measurements.php(490): Cooked_Measurements->math('/12')

4 /plugins/cooked/includes/class.cooked-recipes.php(834): Cooked_Measurements->calculate('1 /12', 'decimal')

5 /plugins/cooked/includes/class.cooked-seo.php(56): Cooked_Recipes::single_ingredient(Array, false, true)

6 /plugins/cooked/templates/front/recipe.php(20): Cooked_SEO::schema_values(Array)`

XjSv commented 2 months ago

I can confirm this is an issue. I going to attempt to include this in the next upcoming release v1.8.0.