瀏覽代碼

Validate date/time fields using their regular expression during an import (or synchro) to avoid passing wrong formats as-is (e.g. 01/02/16 can become 01/02/0016 instead of 01/02/2016 if you use the 4 digits format for years and pass only 2 digits !)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4096 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 年之前
父節點
當前提交
f4382de1bf
共有 2 個文件被更改,包括 16 次插入5 次删除
  1. 2 0
      core/bulkchange.class.inc.php
  2. 14 5
      synchro/synchro_import.php

+ 2 - 0
core/bulkchange.class.inc.php

@@ -827,6 +827,8 @@ class BulkChange
 							{
 								$sFormat = $sDateFormat;
 							}
+							$oFormat = new DateTimeFormat($sFormat);
+							$sRegExp = $oFormat->ToRegExpr();
 							if (!preg_match('/'.$sRegExp.'/', $this->m_aData[$iRow][$iCol]))
 							{
 								$aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));

+ 14 - 5
synchro/synchro_import.php

@@ -217,15 +217,24 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
 function ChangeDateFormat($sProposedDate, $sDateFormat)
 {
 	// Make sure this is a valid MySQL datetime
-	$oDate = DateTime::createFromFormat($sDateFormat, $sProposedDate);
-	if ($oDate !== false)
+	$oFormat = new DateTimeFormat($sDateFormat);
+	$sRegExpr = $oFormat->ToRegExpr();
+	if (!preg_match('/'.$sRegExpr.'/', $sProposedDate))
 	{
-		$sDate = $oDate->format(AttributeDateTime::GetInternalFormat());
-		return $sDate;
+		return false;	
 	}
 	else
 	{
-		return false;
+		$oDate = DateTime::createFromFormat($sDateFormat, $sProposedDate);
+		if ($oDate !== false)
+		{
+			$sDate = $oDate->format(AttributeDateTime::GetInternalFormat());
+			return $sDate;
+		}
+		else
+		{
+			return false;
+		}
 	}
 }