FIX isInt() does not detect sized integer types (tinyint, bigint) (#39236)
CommonObject::isInt() decides whether a list-page column gets numeric search mode and is also used when resolving $this->id. The regex /(^int|int$)/ missed sized integer types such as tinyint(4) and bigint(20): they neither start nor end with "int". These types are not exotic: tinyint(4) is used in several core $fields definitions (societe, contact, entrepot, companypaymentmode, ...) and ModuleBuilder-generated tables use bigint(20) for rowid, so isInt() should recognise them rather than requiring callers to change the column type. The new regex /^(?:tiny|small|medium|big)?int|int$/ also handles smallint/mediumint with a size. Anchoring is preserved on purpose so that strings which merely contain "int" (e.g. sellist:Table:...) are still NOT matched, while the Dolibarr foreign-key syntax "integer:Class:path" keeps being detected. Signed-off-by: Jam Balaya <jambalaya.pyoncafe@outlook.jp>
This commit is contained in:
parent
a270e0852b
commit
797312579b
2 changed files with 35 additions and 1 deletions
|
|
@ -10059,7 +10059,7 @@ abstract class CommonObject
|
|||
public function isInt($info)
|
||||
{
|
||||
if (is_array($info)) {
|
||||
if (isset($info['type']) && (preg_match('/(^int|int$)/i', $info['type']))) {
|
||||
if (isset($info['type']) && (preg_match('/^(?:tiny|small|medium|big)?int|int$/i', $info['type']))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -117,4 +117,38 @@ class CommonObjectTest extends CommonClassTest
|
|||
$this->assertLessThanOrEqual($result, 0);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsInt
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsInt()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf = $this->savconf;
|
||||
$user = $this->savuser;
|
||||
$langs = $this->savlangs;
|
||||
$db = $this->savdb;
|
||||
|
||||
$localobject = new Commande($db);
|
||||
|
||||
// Integer types, with or without a size/unsigned suffix, must be detected.
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'int')), 'int');
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'int(11)')), 'int(11)');
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'integer')), 'integer');
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'tinyint(4)')), 'tinyint(4)');
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'smallint(6)')), 'smallint(6)');
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'bigint(20)')), 'bigint(20)');
|
||||
// Dolibarr foreign-key column syntax "integer:Class:path" must keep being detected.
|
||||
$this->assertTrue($localobject->isInt(array('type' => 'integer:User:user/class/user.class.php')), 'integer:User:...');
|
||||
|
||||
// Non-integer types must not be detected, including strings that merely contain "int".
|
||||
$this->assertFalse($localobject->isInt(array('type' => 'varchar(255)')), 'varchar(255)');
|
||||
$this->assertFalse($localobject->isInt(array('type' => 'double(24,8)')), 'double(24,8)');
|
||||
$this->assertFalse($localobject->isInt(array('type' => 'date')), 'date');
|
||||
$this->assertFalse($localobject->isInt(array('type' => 'sellist:llx_c_typent:libelle:id')), 'sellist:...');
|
||||
|
||||
print __METHOD__." OK\n";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue