Merge "Handle a negative exponent in TempUser/ScrambleMapping.php"
This commit is contained in:
commit
2d5499a89a
2 changed files with 10 additions and 0 deletions
|
|
@ -76,6 +76,9 @@ class ScrambleMapping implements SerialMapping {
|
|||
return (string)$index;
|
||||
}
|
||||
$offset = $this->offset;
|
||||
if ( $index - $offset < 0 ) {
|
||||
throw new \MWException( __METHOD__ . ": The configured offset $offset is too large." );
|
||||
}
|
||||
foreach ( self::GENERATORS as [ $g, $p ] ) {
|
||||
if ( $index - $offset < $p ) {
|
||||
return (string)( $offset + $this->powmod( $g, $index - $offset, $p ) );
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace MediaWiki\Tests\User\TempUser;
|
||||
|
||||
use MediaWiki\User\TempUser\ScrambleMapping;
|
||||
use MWException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -31,4 +32,10 @@ class ScrambleMappingTest extends TestCase {
|
|||
}
|
||||
$this->assertSame( 0, $duplicates, 'duplicate detected' );
|
||||
}
|
||||
|
||||
public function testOffsetTooLarge() {
|
||||
$map = new ScrambleMapping( [ 'offset' => 10 ] );
|
||||
$this->expectException( MWException::class );
|
||||
$map->getSerialIdForIndex( 1 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue