From 2465282a1fa8d4e24e65b6e80bdabb74a42e27cc Mon Sep 17 00:00:00 2001 From: Muhammad Imangazaliev Date: Tue, 9 Feb 2021 22:51:00 +0300 Subject: [PATCH] Handle nested pseudo-classes with expression correctly --- src/DiDom/Query.php | 6 +++--- tests/QueryTest.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/DiDom/Query.php b/src/DiDom/Query.php index 85f2d1c..1a7e9f2 100644 --- a/src/DiDom/Query.php +++ b/src/DiDom/Query.php @@ -466,11 +466,11 @@ public static function getSegments($selector) $classes = '(?P\.[\w|\-|\.]+)*'; $attrs = '(?P(?:\[.+?\])*)?'; $name = '(?P[\w\-]+)'; - $expr = '(?:\((?P[^\)]+)\))'; - $pseudo = '(?::'.$name.$expr.'?)?'; + $expr = '(?:\((?P.+)\))'; + $pseudo = '(?::' . $name . $expr . '?)?'; $rel = '\s*(?P>)?'; - $regexp = '/'.$tag.$id.$classes.$attrs.$pseudo.$rel.'/is'; + $regexp = '/' . $tag . $id . $classes . $attrs . $pseudo . $rel . '/is'; if (preg_match($regexp, $selector, $segments)) { if ($segments[0] === '') { diff --git a/tests/QueryTest.php b/tests/QueryTest.php index b8da361..6df5bf9 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -291,6 +291,8 @@ public function compileCssTests() $compiled = array_merge($compiled, [ ['a[title="foo, bar::baz"]', '//a[@title="foo, bar::baz"]'], + // nested pseudo-class with expression + [':not(:contains(foo))', '//*[not(self::*[contains(text(), "foo")])]'], ]); return $compiled;