Skip to content

Commit 764f0b9

Browse files
authored
Merge pull request #161 from GravityPDF/backport/php-8.6-4.3
[4.3] Add PHP 8.6 support
2 parents 6599a11 + 8cdafef commit 764f0b9

6 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎.github/workflows/coding-standard.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout repository
11-
uses: actions/checkout@v6
11+
uses: actions/checkout@v7
1212

1313
- name: Setup PHP
1414
uses: shivammathur/setup-php@v2

‎.github/workflows/unit-testing.yml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ on: [ pull_request ]
44

55
jobs:
66
phpunit:
7-
runs-on: ubuntu-latest
7+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
88
strategy:
99
matrix:
10-
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
10+
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6' ]
1111
include:
12-
- php: '8.3'
12+
# libxml2 2.14+ (ubuntu-26.04 onwards) parses HTML as HTML5, which skips the tests for
13+
# libxml's older HTML parser, so the coverage job stays on a runner that still has it.
14+
- php-versions: '8.3'
15+
os: ubuntu-24.04
1316
report: true
1417

1518
name: PHP ${{ matrix.php-versions }} PHPUnit Test
1619
steps:
1720
- name: Checkout repository
18-
uses: actions/checkout@v6
21+
uses: actions/checkout@v7
1922

2023
- name: Setup PHP
2124
uses: shivammathur/setup-php@v2
@@ -41,7 +44,7 @@ jobs:
4144

4245
- name: Check Code Coverage
4346
if: ${{ matrix.report }}
44-
uses: codecov/codecov-action@v5
47+
uses: codecov/codecov-action@v7
4548
with:
4649
directory: ./coverage/
4750
token: ${{ secrets.CODECOV_TOKEN }}

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ QueryPath Changelog
33

44
# Unreleased changes
55

6-
-
6+
- Add support for PHP 8.6
7+
- With libxml2 2.14+, `htmlqp()` parses `<?php ... ?>` as a comment (`<!--?php ... ?-->`) and no longer throws `QueryPath\ParseException` on malformed HTML. Use `html5qp()` to keep processing instructions
78

89
# 4.1.0
910

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gravitypdf/querypath",
33
"type": "library",
4-
"description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.5 support",
4+
"description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.6 support",
55
"homepage": "https://github.com/gravitypdf/querypath",
66
"license": "MIT",
77
"keywords": [
@@ -23,7 +23,7 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
26+
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0",
2727
"masterminds/html5": "^2.0"
2828
},
2929
"autoload": {

‎tests/QueryPath/DOMQueryTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ public function testFailedHTTPLoadWithContext()
287287

288288
public function testFailedParseHTMLElement()
289289
{
290+
$this->requireLegacyHtmlParser();
291+
290292
$this->expectException(ParseException::class);
291293

292294
try {

‎tests/QueryPath/TestCase.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,33 @@ class TestCase extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
1111
{
1212
public const DATA_FILE_XML = 'tests/data.xml';
1313
public const DATA_FILE_HTML = 'tests/data.html';
14+
15+
/**
16+
* Whether libxml's HTML parser follows HTML5, as it does from 2.14.
17+
*
18+
* Such a parser reads `<?...>` as a comment rather than a processing instruction, and reports no
19+
* parse errors. Probed rather than read from LIBXML_VERSION, which is the version PHP was built
20+
* against, not necessarily the one it runs with.
21+
*
22+
* @return bool
23+
*/
24+
protected static function libxmlParsesHtmlAsHtml5(): bool
25+
{
26+
static $html5;
27+
28+
if ($html5 === null) {
29+
$document = new \DOMDocument();
30+
@$document->loadHTML('<p><?x y?></p>');
31+
$html5 = ! $document->getElementsByTagName('p')->item(0)->firstChild instanceof \DOMProcessingInstruction;
32+
}
33+
34+
return $html5;
35+
}
36+
37+
protected function requireLegacyHtmlParser()
38+
{
39+
if (self::libxmlParsesHtmlAsHtml5()) {
40+
$this->markTestSkipped('libxml ' . LIBXML_DOTTED_VERSION . ' parses HTML as HTML5.');
41+
}
42+
}
1443
}

0 commit comments

Comments
 (0)