Skip to content

Commit 97583be

Browse files
committed
CssXPath: Implement ~ Subsequent-sibling
fix FreshRSS#8143 Upstream PR phpgt/CssXPath#231
1 parent 9833d81 commit 97583be

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

lib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ marienfressinaud/lib_opml/tests/
1212
phpgt/cssxpath/.*
1313
phpgt/cssxpath/composer.json
1414
phpgt/cssxpath/CONTRIBUTING.md
15+
phpgt/cssxpath/phpunit.xml
16+
phpgt/cssxpath/SECURITY*
1517
phpgt/cssxpath/test/
1618
phpmailer/phpmailer/*oauth*
1719
phpmailer/phpmailer/COMMITMENT*

lib/composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
"homepage": "https://freshrss.org/",
66
"license": "AGPL-3.0",
77
"repositories": [
8+
{
9+
"type": "git",
10+
"url": "https://github.com/phpgt/CssXPath.git"
11+
},
812
{
913
"type": "git",
1014
"url": "https://github.com/FreshRSS/simplepie.git"
1115
}
1216
],
1317
"require": {
1418
"marienfressinaud/lib_opml": "0.5.1",
15-
"phpgt/cssxpath": "v1.3.0",
19+
"phpgt/cssxpath": "dev-master#008aaf7f381e2396590fc53830f4a8ad9f517c7f",
1620
"phpmailer/phpmailer": "6.11.1",
1721
"simplepie/simplepie": "dev-freshrss#24cfb0c6d81f81ef110c8257d3464b2649476c77"
1822
},
@@ -21,6 +25,9 @@
2125
"vendor-dir": "./"
2226
},
2327
"scripts": {
24-
"post-update-cmd": "git clean -d -f -X ."
28+
"post-update-cmd": [
29+
"git clean -d -ff -X .",
30+
"find . -name '.git' -type d -exec rm -rf {} + || true"
31+
]
2532
}
2633
}

lib/phpgt/cssxpath/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Translate CSS selectors to XPath queries
2-
========================================
1+
Translate CSS selectors to XPath queries.
2+
=========================================
33

44
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.
55

@@ -61,3 +61,9 @@ It's perhaps worth noting that for XML-style matching to work, you must load the
6161

6262
[qsa]: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
6363
[gt-dom]: https://www.php.gt/dom
64+
65+
# Proudly sponsored by
66+
67+
[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)
68+
69+
[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://www.jetbrains.com/community/opensource/)

lib/phpgt/cssxpath/src/Translator.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Translator {
1212
. '|(#(?P<id>[\w-]*))'
1313
. '|(\.(?P<class>[\w-]*))'
1414
. '|(?P<sibling>\s*\+\s*)'
15+
. '|(?P<subsequentsibling>\s*~\s*)'
1516
. "|(\[(?P<attribute>[\w-]*)((?P<attribute_equals>[=~$|^*]+)(?P<attribute_value>(.+\[\]'?)|[^\]]+))*\])+"
1617
. '|(?P<descendant>\s+)'
1718
. '/';
@@ -24,8 +25,8 @@ class Translator {
2425
const EQUALS_STARTS_WITH = "^=";
2526

2627
public function __construct(
27-
protected string $cssSelector,
28-
protected string $prefix = ".//",
28+
protected string $cssSelector,
29+
protected string $prefix = ".//",
2930
protected bool $htmlMode = true
3031
) {
3132
}
@@ -198,7 +199,7 @@ protected function convertSingleSelector(string $css):string {
198199
"[last()]"
199200
);
200201
}
201-
break;
202+
break;
202203

203204
}
204205
break;
@@ -235,6 +236,14 @@ protected function convertSingleSelector(string $css):string {
235236
$hasElement = false;
236237
break;
237238

239+
case "subsequentsibling":
240+
array_push(
241+
$xpath,
242+
"/following-sibling::"
243+
);
244+
$hasElement = false;
245+
break;
246+
238247
case "attribute":
239248
if(!$hasElement) {
240249
array_push($xpath, "*");

0 commit comments

Comments
 (0)