Commit 50ab0be6 authored by alexpott's avatar alexpott
Browse files

Issue #1988780 by pfrenssen: Fixed DrupalWebTestCase::buildXPathQuery() tries...

Issue #1988780 by pfrenssen: Fixed DrupalWebTestCase::buildXPathQuery() tries to handle backreferences in argument values.
parent 87417aaf
......@@ -52,6 +52,8 @@ function testXPathEscaping() {
<body>
<a href="link1">A "weird" link, just to bother the dumb "XPath 1.0"</a>
<a href="link2">A second "even more weird" link, in memory of George O'Malley</a>
<a href="link3">A \$third$ link, so weird it's worth $1 million</a>
<a href="link4">A fourth link, containing alternative \\1 regex backreferences \\2</a>
</body>
</html>
EOF;
......@@ -63,5 +65,11 @@ function testXPathEscaping() {
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A second "even more weird" link, in memory of George O\'Malley'));
$this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.');
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A $third$ link, so weird it\'s worth $1 million'));
$this->assertEqual($urls[0]['href'], 'link3', 'Match with a regular expression back reference symbol (dollar sign).');
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A fourth link, containing alternative \\1 regex backreferences \\2'));
$this->assertEqual($urls[0]['href'], 'link4', 'Match with another regular expression back reference symbol (double backslash).');
}
}
......@@ -1900,7 +1900,13 @@ protected function buildXPathQuery($xpath, array $args = array()) {
// Return the string.
$value = count($parts) > 1 ? 'concat(' . implode(', \'"\', ', $parts) . ')' : $parts[0];
}
$xpath = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $xpath);
// Use preg_replace_callback() instead of preg_replace() to prevent the
// regular expression engine from trying to substitute backreferences.
$replacement = function ($matches) use ($value) {
return $value;
};
$xpath = preg_replace_callback('/' . preg_quote($placeholder) . '\b/', $replacement, $xpath);
}
return $xpath;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment