From f78611e43b7f6eac198011aab623f81eb904a720 Mon Sep 17 00:00:00 2001 From: Joris Berthelot Date: Tue, 14 Jun 2022 21:46:29 +0200 Subject: [PATCH] [CssSelector] [HashParser] Added parsing support for dotted hashes --- .../Component/CssSelector/Parser/Shortcut/HashParser.php | 2 +- .../CssSelector/Tests/Parser/Shortcut/HashParserTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/CssSelector/Parser/Shortcut/HashParser.php b/src/Symfony/Component/CssSelector/Parser/Shortcut/HashParser.php index fb07ee6cf86ff..a4f370489d713 100644 --- a/src/Symfony/Component/CssSelector/Parser/Shortcut/HashParser.php +++ b/src/Symfony/Component/CssSelector/Parser/Shortcut/HashParser.php @@ -40,7 +40,7 @@ public function parse(string $source): array // 1 => string 'test' (length=4) // 2 => string 'input' (length=5) // 3 => string 'ab6bd_field' (length=11) - if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w-]++)$/i', trim($source), $matches)) { + if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w.-]++)$/i', trim($source), $matches)) { return [ new SelectorNode(new HashNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])), ]; diff --git a/src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/HashParserTest.php b/src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/HashParserTest.php index a7c79d69a547a..5499a7840bf13 100644 --- a/src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/HashParserTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/HashParserTest.php @@ -36,10 +36,15 @@ public function getParseTestData() { return [ ['#testid', 'Hash[Element[*]#testid]'], + ['#test.id', 'Hash[Element[*]#test.id]'], ['testel#testid', 'Hash[Element[testel]#testid]'], + ['testel#test.id', 'Hash[Element[testel]#test.id]'], ['testns|#testid', 'Hash[Element[testns|*]#testid]'], + ['testns|#test.id', 'Hash[Element[testns|*]#test.id]'], ['testns|*#testid', 'Hash[Element[testns|*]#testid]'], + ['testns|*#test.id', 'Hash[Element[testns|*]#test.id]'], ['testns|testel#testid', 'Hash[Element[testns|testel]#testid]'], + ['testns|testel#test.id', 'Hash[Element[testns|testel]#test.id]'], ]; } }