瀏覽代碼

N.497 Continuation of the fix done in [r4461], to correctly handle validation patterns containing a slash (AttributeURL in the enhanced customer portal). The initial fix has broken the validation of date (+time) fields because the slash was escaped twice, leading to an invalid regular expression. Requires testing of synchro, CSV import, console, customer portal...

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4538 a333f486-631f-4898-b8df-5754b55c2be0
romainq 8 年之前
父節點
當前提交
f6c4655769
共有 4 個文件被更改,包括 16 次插入10 次删除
  1. 2 2
      core/bulkchange.class.inc.php
  2. 8 2
      core/datetimeformat.class.inc.php
  3. 2 2
      synchro/synchro_import.php
  4. 4 4
      test/testlist.inc.php

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

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

+ 8 - 2
core/datetimeformat.class.inc.php

@@ -413,10 +413,16 @@ EOF
 	/**
 	/**
 	 * Get the regular expression to (approximately) validate a date/time for the current format
 	 * Get the regular expression to (approximately) validate a date/time for the current format
 	 * The validation does not take into account the number of days in a month (i.e. June 31st will pass, as well as Feb 30th!)
 	 * The validation does not take into account the number of days in a month (i.e. June 31st will pass, as well as Feb 30th!)
+	 * @param string $sDelimiter Surround the regexp (and escape) if needed
 	 * @return string The regular expression in PCRE syntax
 	 * @return string The regular expression in PCRE syntax
 	 */
 	 */
-	public function ToRegExpr()
+	public function ToRegExpr($sDelimiter = null)
 	{
 	{
-		return '^'.$this->Transform('regexpr', "\\%s", false /* escape all */, '.?*$^()[]/:').'$';
+		$sRet = '^'.$this->Transform('regexpr', "\\%s", false /* escape all */, '.?*$^()[]:').'$';
+		if ($sDelimiter !== null)
+		{
+			$sRet = $sDelimiter.str_replace($sDelimiter, '\\'.$sDelimiter, $sRet).$sDelimiter;
+		}
+		return $sRet;
 	}
 	}
 }
 }

+ 2 - 2
synchro/synchro_import.php

@@ -218,8 +218,8 @@ function ChangeDateFormat($sProposedDate, $sFormat)
 {
 {
 	// Convert to a valid MySQL datetime
 	// Convert to a valid MySQL datetime
 	$oFormat = new DateTimeFormat($sFormat);
 	$oFormat = new DateTimeFormat($sFormat);
-	$sRegExpr = $oFormat->ToRegExpr();
-	if (!preg_match('/'.$sRegExpr.'/', $sProposedDate))
+	$sRegExpr = $oFormat->ToRegExpr('/');
+	if (!preg_match($sRegExpr, $sProposedDate))
 	{
 	{
 		return false;	
 		return false;	
 	}
 	}

+ 4 - 4
test/testlist.inc.php

@@ -4930,14 +4930,14 @@ class TestDateTimeFormats extends TestBizModel
 				$oDate = new DateTime($sTestDate);
 				$oDate = new DateTime($sTestDate);
 				$sFormattedDate = $oFormat->Format($oDate);
 				$sFormattedDate = $oFormat->Format($oDate);
 				$oParsedDate = $oFormat->Parse($sFormattedDate);
 				$oParsedDate = $oFormat->Parse($sFormattedDate);
-				$sPattern = $oFormat->ToRegExpr();
+				$sPattern = $oFormat->ToRegExpr('/');
 				$bParseOk = ($oParsedDate->format('Y-m-d H:i:s') == $sTestDate);
 				$bParseOk = ($oParsedDate->format('Y-m-d H:i:s') == $sTestDate);
 				if (!$bParseOk)
 				if (!$bParseOk)
 				{
 				{
 					$this->ReportError('Parsed ('.$sFormattedDate.') date different from initial date (difference of '.((int)$oParsedDate->format('U')- (int)$oDate->format('U')).'s)');
 					$this->ReportError('Parsed ('.$sFormattedDate.') date different from initial date (difference of '.((int)$oParsedDate->format('U')- (int)$oDate->format('U')).'s)');
 					$bRet = false;
 					$bRet = false;
 				}
 				}
-				$bValidateOk = preg_match('/'.$sPattern.'/', $sFormattedDate);
+				$bValidateOk = preg_match($sPattern, $sFormattedDate);
 				if (!$bValidateOk)
 				if (!$bValidateOk)
 				{
 				{
 					$this->ReportError('Formatted date ('.$sFormattedDate.') does not match the validation pattern ('.$sPattern.')');
 					$this->ReportError('Formatted date ('.$sFormattedDate.') does not match the validation pattern ('.$sPattern.')');
@@ -4963,8 +4963,8 @@ class TestDateTimeFormats extends TestBizModel
 			$this->ReportSuccess("Test of the '$sFormatName' format: '$sFormat':");
 			$this->ReportSuccess("Test of the '$sFormatName' format: '$sFormat':");
 			foreach($aDatesToParse as $sDate)
 			foreach($aDatesToParse as $sDate)
 			{
 			{
-				$sPattern = $oFormat->ToRegExpr();
-				$bValidateOk = preg_match('/'.$sPattern.'/', $sDate);
+				$sPattern = $oFormat->ToRegExpr('/');
+				$bValidateOk = preg_match($sPattern, $sDate);
 				if ($bValidateOk)
 				if ($bValidateOk)
 				{
 				{
 					$this->ReportError('Formatted date ('.$sFormattedDate.') matches the validation pattern ('.$sPattern.') whereas it should not!');
 					$this->ReportError('Formatted date ('.$sFormattedDate.') matches the validation pattern ('.$sPattern.') whereas it should not!');