Skip to content

Commit 9dc472a

Browse files
Franck RANAIVO-HARISOAFranck
authored andcommitted
Fix: remove unused method
1 parent 0605aca commit 9dc472a

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

src/Symfony/Component/CssSelector/Exception/SyntaxErrorException.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ public static function notAtTheStartOfASelector(string $pseudoElement): self
4848
return new self(\sprintf('Got immediate child pseudo-element ":%s" not at the start of a selector', $pseudoElement));
4949
}
5050

51-
public static function nestedHas(): self
52-
{
53-
return new self('Got nested :has().');
54-
}
55-
5651
public static function stringAsFunctionArgument(): self
5752
{
5853
return new self('String not allowed as function argument.');

src/Symfony/Component/CssSelector/Parser/Parser.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\CssSelector\Parser;
1313

14+
use Symfony\Component\CssSelector\Exception\InternalErrorException;
1415
use Symfony\Component\CssSelector\Exception\SyntaxErrorException;
1516
use Symfony\Component\CssSelector\Node;
1617
use Symfony\Component\CssSelector\Parser\Tokenizer\Tokenizer;
@@ -144,10 +145,42 @@ private function parserSelectorNode(TokenStream $stream, bool $isArgument = fals
144145
return new Node\SelectorNode($result, $pseudoElement);
145146
}
146147

148+
/**
149+
* @throws InternalErrorException
150+
* @throws SyntaxErrorException
151+
*/
152+
function parseRelativeSelector(TokenStream $stream): array
153+
{
154+
$stream->skipWhitespace();
155+
$subSelector = '';
156+
$next = $stream->getNext();
157+
158+
if ($next->isDelimiter(['-', '+', '>', '~'])) {
159+
$combinator = $next->getValue();
160+
$stream->skipWhitespace();
161+
$next = $stream->getNext();
162+
} else {
163+
$combinator = new Token(Token::TYPE_DELIMITER, ' ', 0);
164+
}
165+
166+
while(true){
167+
if ($next->isString() || $next->isIdentifier() || $next->isNumber()
168+
|| $next->isDelimiter(['.', '*'])) {
169+
$subSelector .= $next->getValue();
170+
} elseif ($next->isDelimiter([')'])) {
171+
$result = $this->parse($subSelector);
172+
return [$combinator, $result[0]];
173+
} else {
174+
throw SyntaxErrorException::unexpectedToken('an argument', $next);
175+
}
176+
$next = $stream->getNext();
177+
}
178+
}
179+
147180
/**
148181
* Parses next simple node (hash, class, pseudo, negation).
149182
*
150-
* @throws SyntaxErrorException
183+
* @throws SyntaxErrorException|InternalErrorException
151184
*/
152185
private function parseSimpleSelector(TokenStream $stream, bool $insideNegation = false, bool $isArgument = false): array
153186
{
@@ -253,6 +286,9 @@ private function parseSimpleSelector(TokenStream $stream, bool $insideNegation =
253286
}
254287

255288
$result = new Node\SpecificityAdjustmentNode($result, $selectors);
289+
} elseif('has' === strtolower($identifier)) {
290+
[$combinator, $arguments] = $this->parseRelativeSelector($stream);
291+
$result = new Node\RelationNode($result, $combinator ,$arguments);
256292
} else {
257293
$arguments = [];
258294
$next = null;

src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ public static function getCssToXPathTestData()
235235
[':scope', '*[1]'],
236236
['e:is(section, article) h1', "e[(name() = 'section') or (name() = 'article')]/descendant-or-self::*/h1"],
237237
['e:where(section, article) h1', "e[(name() = 'section') or (name() = 'article')]/descendant-or-self::*/h1"],
238+
['div:has(> .foo)', "div[./*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]]"],
239+
['div:has(~ .foo)', "div[following-sibling::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]]"],
240+
['div:has(+ .foo)', "div[following-sibling::*[(@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')) and (position() = 1)]]"],
241+
['div:has(+ .foo)', "div[following-sibling::*[(@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')) and (position() = 1)]]"],
238242
];
239243
}
240244

src/Symfony/Component/CssSelector/XPath/Extension/AbstractExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* XPath expression translator abstract extension.
1616
*
1717
* This component is a port of the Python cssselect library,
18-
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
18+
* which is copyright Ian Bicking, @see https://github.com/scrapy/cssselect.
1919
*
2020
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
2121
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy