aboutsummaryrefslogtreecommitdiff
path: root/lib/phpgt
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-10-25 11:22:09 +0200
committerGravatar GitHub <noreply@github.com> 2025-10-25 11:22:09 +0200
commit1abb261ceaaa30ca2ad8ed14b0162ed81bb4724a (patch)
tree40e5e130abe8458cbcc11738f0fd3c4264791ed4 /lib/phpgt
parentf1c91c84ddee0a9f3ef6d0775f630822c184963f (diff)
CssXPath: Implement ~ subsequent-sibling (#8154)
* CssXPath: Implement ~ Subsequent-sibling fix https://github.com/FreshRSS/FreshRSS/issues/8143 Upstream PR https://github.com/phpgt/CssXPath/pull/231 * Use CssXPath release v1.4.0 https://github.com/phpgt/CssXPath/releases/tag/v1.4.0
Diffstat (limited to 'lib/phpgt')
-rw-r--r--lib/phpgt/cssxpath/README.md10
-rw-r--r--lib/phpgt/cssxpath/src/Translator.php15
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/phpgt/cssxpath/README.md b/lib/phpgt/cssxpath/README.md
index 048547442..a1777c423 100644
--- a/lib/phpgt/cssxpath/README.md
+++ b/lib/phpgt/cssxpath/README.md
@@ -1,5 +1,5 @@
-Translate CSS selectors to XPath queries
-========================================
+Translate CSS selectors to XPath queries.
+=========================================
A lightweight and dependency free CSS to XPath translator. This repository is used to bring modern DOM functionality like [`querySelectorAll()`][qsa] to PHP in the [PHP.Gt/Dom][gt-dom] project.
@@ -61,3 +61,9 @@ It's perhaps worth noting that for XML-style matching to work, you must load the
[qsa]: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
[gt-dom]: https://www.php.gt/dom
+
+# Proudly sponsored by
+
+[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)
+
+[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://www.jetbrains.com/community/opensource/)
diff --git a/lib/phpgt/cssxpath/src/Translator.php b/lib/phpgt/cssxpath/src/Translator.php
index 7bb11265c..e5802fd77 100644
--- a/lib/phpgt/cssxpath/src/Translator.php
+++ b/lib/phpgt/cssxpath/src/Translator.php
@@ -12,6 +12,7 @@ class Translator {
. '|(#(?P<id>[\w-]*))'
. '|(\.(?P<class>[\w-]*))'
. '|(?P<sibling>\s*\+\s*)'
+ . '|(?P<subsequentsibling>\s*~\s*)'
. "|(\[(?P<attribute>[\w-]*)((?P<attribute_equals>[=~$|^*]+)(?P<attribute_value>(.+\[\]'?)|[^\]]+))*\])+"
. '|(?P<descendant>\s+)'
. '/';
@@ -24,8 +25,8 @@ class Translator {
const EQUALS_STARTS_WITH = "^=";
public function __construct(
- protected string $cssSelector,
- protected string $prefix = ".//",
+ protected string $cssSelector,
+ protected string $prefix = ".//",
protected bool $htmlMode = true
) {
}
@@ -198,7 +199,7 @@ class Translator {
"[last()]"
);
}
- break;
+ break;
}
break;
@@ -235,6 +236,14 @@ class Translator {
$hasElement = false;
break;
+ case "subsequentsibling":
+ array_push(
+ $xpath,
+ "/following-sibling::"
+ );
+ $hasElement = false;
+ break;
+
case "attribute":
if(!$hasElement) {
array_push($xpath, "*");