mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-18 23:49:14 +02:00
N°9759 - Truncate AttributeText don't work as expected in case of multibytes characters
This commit is contained in:
@@ -897,6 +897,19 @@ abstract class AttributeDefinition
|
||||
return null;
|
||||
}
|
||||
|
||||
public function TrimValue(string $sValue)
|
||||
{
|
||||
$iMaxSize = $this->GetMaxSize();
|
||||
$sLength = mb_strlen($sValue);
|
||||
if ($iMaxSize && ($sLength > $iMaxSize)) {
|
||||
$sMessage = " -truncated ($sLength chars)";
|
||||
|
||||
return mb_substr($sValue, 0, $iMaxSize - mb_strlen($sMessage)).$sMessage;
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
* @deprecated never used
|
||||
@@ -4219,6 +4232,21 @@ class AttributeText extends AttributeString
|
||||
return "TEXT".CMDBSource::GetSqlStringColumnDefinition();
|
||||
}
|
||||
|
||||
public function TrimValue(string $sValue)
|
||||
{
|
||||
$iMaxSize = $this->GetMaxSize();
|
||||
$sLength = strlen($sValue);
|
||||
if ($iMaxSize && ($sLength > $iMaxSize)) {
|
||||
$sMessage = " -truncated ($sLength chars)";
|
||||
$sVal = substr($sValue, 0, $iMaxSize - strlen($sMessage));
|
||||
|
||||
//executes the "mb_substr" function to ensure a character is not truncated in the middle.
|
||||
return mb_substr($sValue, 0, mb_strlen($sVal) - 1).$sMessage;
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
public function GetSQLColumns($bFullSpec = false)
|
||||
{
|
||||
$aColumns = [];
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user