diff --git a/includes/parser/AFPData.php b/includes/parser/AFPData.php index 238279814..fdb89c0e0 100644 --- a/includes/parser/AFPData.php +++ b/includes/parser/AFPData.php @@ -312,7 +312,10 @@ class AFPData { $b = $b->toNumber(); - if ( $op !== '*' && (float)$b === 0.0 ) { + if ( + ( $op === '/' && (float)$b === 0.0 ) || + ( $op === '%' && (int)$b === 0 ) + ) { $lhs = $this->type === self::DUNDEFINED ? 0 : $this->toNumber(); throw new AFPUserVisibleException( 'dividebyzero', $pos, [ $lhs ] ); } diff --git a/tests/phpunit/unit/AFPDataTest.php b/tests/phpunit/unit/AFPDataTest.php index 53f1b5ba3..e31b236d5 100644 --- a/tests/phpunit/unit/AFPDataTest.php +++ b/tests/phpunit/unit/AFPDataTest.php @@ -50,7 +50,7 @@ class AFPDataTest extends AbuseFilterParserTestCase { } /** - * Data provider for testRegexFailureException + * Data provider for testDivideByZeroException * The second parameter is the function where the exception is raised. * One expression for each throw. * @@ -60,6 +60,11 @@ class AFPDataTest extends AbuseFilterParserTestCase { return [ [ '1/0', 'mulRel' ], [ '1/0.0', 'mulRel' ], + [ '1/(-0.0)', 'mulRel' ], + [ '1%0', 'mulRel' ], + [ '1%0.0', 'mulRel' ], + [ '1%0.3', 'mulRel' ], + [ '1%(-0.7)', 'mulRel' ], ]; }