Przeglądaj źródła

Internal: correctly quote XPath literals within GetNodeById

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3049 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 lat temu
rodzic
commit
cdb6b8d01b
1 zmienionych plików z 16 dodań i 1 usunięć
  1. 16 1
      setup/modelfactory.class.inc.php

+ 16 - 1
setup/modelfactory.class.inc.php

@@ -2221,7 +2221,8 @@ class MFDocument extends DOMDocument
 	public function GetNodeById($sXPath, $sId, $oContextNode = null)
 	{
 		$oXPath = new DOMXPath($this);
-		$sXPath .= "[@id='$sId' and(not(@_alteration) or @_alteration!='removed')]";
+		$sQuotedId = self::XPathQuote($sId);
+		$sXPath .= "[@id=$sQuotedId and(not(@_alteration) or @_alteration!='removed')]";
 		
 		if (is_null($oContextNode))
 		{
@@ -2232,4 +2233,18 @@ class MFDocument extends DOMDocument
 			return $oXPath->query($sXPath, $oContextNode);
 		}
 	}
+
+	public static function XPathQuote($sValue)
+	{
+		if (strpos($sValue, '"') !== false)
+		{
+			$aParts = explode('"', $sValue);
+			$sRet = 'concat("'.implode('", \'"\', "', $aParts).'")';
+		}
+		else
+		{
+			$sRet = '"'.$sValue.'"';
+		}
+		return $sRet;
+	}
 }