Pārlūkot izejas kodu

#139 Improved string size verification, the rule is guaranteed by the core

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@721 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 gadi atpakaļ
vecāks
revīzija
d329160241
2 mainītis faili ar 40 papildinājumiem un 1 dzēšanām
  1. 31 0
      core/attributedef.class.inc.php
  2. 9 1
      core/dbobject.class.php

+ 31 - 0
core/attributedef.class.inc.php

@@ -213,6 +213,11 @@ abstract class AttributeDefinition
 		return true;
 	}
 	 
+	public function GetMaxSize()
+	{
+		return null;
+	}
+	 
 	public function MakeValue()
 	{
 		$sComputeFunc = $this->Get("compute_func");
@@ -636,6 +641,11 @@ class AttributeString extends AttributeDBField
 		}
 	}
 
+	public function GetMaxSize()
+	{
+		return 255;
+	}
+
 	public function GetBasicFilterOperators()
 	{
 		return array(
@@ -844,6 +854,11 @@ class AttributePassword extends AttributeString
 	public function GetEditClass() {return "Password";}
 	protected function GetSQLCol() {return "VARCHAR(64)";}
 
+	public function GetMaxSize()
+	{
+		return 64;
+	}
+
 	public function GetFilterDefinitions()
 	{
 	// Note: due to this, you will get an error if a password is being declared as a search criteria (see ZLists)
@@ -887,6 +902,11 @@ class AttributeEncryptedString extends AttributeString
 
 	protected function GetSQLCol() {return "TINYBLOB";}	
 
+	public function GetMaxSize()
+	{
+		return 255;
+	}
+
 	public function GetFilterDefinitions()
 	{
 		// Note: due to this, you will get an error if a an encrypted field is declared as a search criteria (see ZLists)
@@ -936,6 +956,13 @@ class AttributeText extends AttributeString
 	public function GetEditClass() {return "Text";}
 	protected function GetSQLCol() {return "TEXT";}
 
+	public function GetMaxSize()
+	{
+		// Is there a way to know the current limitation for mysql?
+		// See mysql_field_len()
+		return 65535;
+	}
+
 	public function GetAsHTML($sValue)
 	{
 		return str_replace("\n", "<br>\n", parent::GetAsHTML($sValue));
@@ -2082,6 +2109,10 @@ class AttributeTable extends AttributeText
 	public function GetEditClass() {return "Text";}
 	protected function GetSQLCol() {return "TEXT";}
 
+	public function GetMaxSize()
+	{
+		return null;
+	}
 
 	// Facilitate things: allow the user to Set the value from a string
 	public function MakeRealValue($proposedValue)

+ 9 - 1
core/dbobject.class.php

@@ -636,7 +636,15 @@ abstract class DBObject
 					return "Value not allowed [$toCheck]";
 				}
 			}
-			elseif (!$oAtt->CheckFormat($toCheck))
+			if (!is_null($iMaxSize = $oAtt->GetMaxSize()))
+			{
+				$iLen = strlen($toCheck);
+				if ($iLen > $iMaxSize)
+				{
+					return "String too long (found $iLen, limited to $iMaxSize)";
+				}
+			}
+			if (!$oAtt->CheckFormat($toCheck))
 			{
 				return "Wrong format [$toCheck]";
 			}