composer-update-patch
This commit is contained in:
58
vendor/symfony/dom-crawler/Crawler.php
vendored
58
vendor/symfony/dom-crawler/Crawler.php
vendored
@@ -940,29 +940,54 @@ class Crawler implements \Countable, \IteratorAggregate
|
||||
{
|
||||
$expressions = array();
|
||||
|
||||
$unionPattern = '/\|(?![^\[]*\])/';
|
||||
// An expression which will never match to replace expressions which cannot match in the crawler
|
||||
// We cannot simply drop
|
||||
$nonMatchingExpression = 'a[name() = "b"]';
|
||||
|
||||
// Split any unions into individual expressions.
|
||||
foreach (preg_split($unionPattern, $xpath) as $expression) {
|
||||
$expression = trim($expression);
|
||||
$parenthesis = '';
|
||||
$xpathLen = strlen($xpath);
|
||||
$openedBrackets = 0;
|
||||
$startPosition = strspn($xpath, " \t\n\r\0\x0B");
|
||||
|
||||
// If the union is inside some braces, we need to preserve the opening braces and apply
|
||||
// the change only inside it.
|
||||
if (preg_match('/^[\(\s*]+/', $expression, $matches)) {
|
||||
$parenthesis = $matches[0];
|
||||
$expression = substr($expression, strlen($parenthesis));
|
||||
for ($i = $startPosition; $i <= $xpathLen; ++$i) {
|
||||
$i += strcspn($xpath, '"\'[]|', $i);
|
||||
|
||||
if ($i < $xpathLen) {
|
||||
switch ($xpath[$i]) {
|
||||
case '"':
|
||||
case "'":
|
||||
if (false === $i = strpos($xpath, $xpath[$i], $i + 1)) {
|
||||
return $xpath; // The XPath expression is invalid
|
||||
}
|
||||
continue 2;
|
||||
case '[':
|
||||
++$openedBrackets;
|
||||
continue 2;
|
||||
case ']':
|
||||
--$openedBrackets;
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
if ($openedBrackets) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($startPosition < $xpathLen && '(' === $xpath[$startPosition]) {
|
||||
// If the union is inside some braces, we need to preserve the opening braces and apply
|
||||
// the change only inside it.
|
||||
$j = 1 + strspn($xpath, "( \t\n\r\0\x0B", $startPosition + 1);
|
||||
$parenthesis = substr($xpath, $startPosition, $j);
|
||||
$startPosition += $j;
|
||||
} else {
|
||||
$parenthesis = '';
|
||||
}
|
||||
$expression = rtrim(substr($xpath, $startPosition, $i - $startPosition));
|
||||
|
||||
if (0 === strpos($expression, 'self::*/')) {
|
||||
$expression = './'.substr($expression, 8);
|
||||
}
|
||||
|
||||
// add prefix before absolute element selector
|
||||
if (empty($expression)) {
|
||||
if ('' === $expression) {
|
||||
$expression = $nonMatchingExpression;
|
||||
} elseif (0 === strpos($expression, '//')) {
|
||||
$expression = 'descendant-or-self::'.substr($expression, 2);
|
||||
@@ -975,7 +1000,7 @@ class Crawler implements \Countable, \IteratorAggregate
|
||||
} elseif ('/' === $expression[0] || '.' === $expression[0] || 0 === strpos($expression, 'self::')) {
|
||||
$expression = $nonMatchingExpression;
|
||||
} elseif (0 === strpos($expression, 'descendant::')) {
|
||||
$expression = 'descendant-or-self::'.substr($expression, strlen('descendant::'));
|
||||
$expression = 'descendant-or-self::'.substr($expression, 12);
|
||||
} elseif (preg_match('/^(ancestor|ancestor-or-self|attribute|following|following-sibling|namespace|parent|preceding|preceding-sibling)::/', $expression)) {
|
||||
// the fake root has no parent, preceding or following nodes and also no attributes (even no namespace attributes)
|
||||
$expression = $nonMatchingExpression;
|
||||
@@ -983,9 +1008,16 @@ class Crawler implements \Countable, \IteratorAggregate
|
||||
$expression = 'self::'.$expression;
|
||||
}
|
||||
$expressions[] = $parenthesis.$expression;
|
||||
|
||||
if ($i === $xpathLen) {
|
||||
return implode(' | ', $expressions);
|
||||
}
|
||||
|
||||
$i += strspn($xpath, " \t\n\r\0\x0B", $i + 1);
|
||||
$startPosition = $i + 1;
|
||||
}
|
||||
|
||||
return implode(' | ', $expressions);
|
||||
return $xpath; // The XPath expression is invalid
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user