Internal: correctly quote XPath literals within GetNodeById

SVN:trunk[3049]
This commit is contained in:
Romain Quetiez
2013-12-17 14:52:20 +00:00
parent e980b051b1
commit 3b65f33325

View File

@@ -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;
}
}