Merge "Check for 0-like floats passed to the modulo operator"

This commit is contained in:
jenkins-bot 2019-11-10 11:51:28 +00:00 committed by Gerrit Code Review
commit 91bc961712
2 changed files with 10 additions and 2 deletions

View file

@ -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 ] );
}

View file

@ -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' ],
];
}