mirror of
https://github.com/Combodo/iTop.git
synced 2026-08-04 04:48:17 +02:00
N°9759 - Truncating AttributeText doesn't work as expected in case of multibytes characters (#964)
* N°9759 - Truncate AttributeText don't work as expected in case of multibytes characters * WIP * Move TrimValue() base definition to AttributeDefinition class, assign DBObject::SetTrim old behavior to it * Fix variable types * Fix variable types * Apply code review fixes, add tests * Define GetSize in AttributeDefinition to easy polymorphic calls instead of obscure AttributeDBFieldVoid * Update php with right since version and ticket, remove useless method overload * Apply suggestions from code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Update core/attributedef.class.inc.php Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Update core/attributedef.class.inc.php Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Apply suggestion from @Molkobain code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Apply suggestion from @Molkobain code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Apply suggestion from @Molkobain code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Apply suggestion from @Molkobain code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Apply suggestion from @Molkobain code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Correctly handle null values in new methods --------- Co-authored-by: Stephen Abello <stephen.abello@combodo.com> Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
This commit is contained in:
@@ -732,13 +732,8 @@ abstract class DBObject implements iDisplay
|
||||
public function SetTrim($sAttCode, $sValue)
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
|
||||
$iMaxSize = $oAttDef->GetMaxSize();
|
||||
$sLength = mb_strlen($sValue);
|
||||
if ($iMaxSize && ($sLength > $iMaxSize)) {
|
||||
$sMessage = " -truncated ($sLength chars)";
|
||||
$sValue = mb_substr($sValue, 0, $iMaxSize - mb_strlen($sMessage)).$sMessage;
|
||||
}
|
||||
$this->Set($sAttCode, $sValue);
|
||||
|
||||
$this->Set($sAttCode, $oAttDef->TrimValue($sValue));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2040,7 +2035,7 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
}
|
||||
if (!is_null($iMaxSize = $oAtt->GetMaxSize())) {
|
||||
$iLen = mb_strlen($toCheck);
|
||||
$iLen = $oAtt->GetSize($toCheck);
|
||||
if ($iLen > $iMaxSize) {
|
||||
return "String too long (found $iLen, limited to $iMaxSize)";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user