Skip to content

Commit 8cdafef

Browse files
Fix CI on ubuntu-26.04, whose libxml2 parses HTML as HTML5
Backport of the applicable parts of 7ffe1aa. GitHub's ubuntu-latest is now ubuntu-26.04, whose libxml2 2.15 no longer reports HTML parse errors, so testFailedParseHTMLElement failed on every PHP version. - Skip that test when libxml parses HTML as HTML5, probed at runtime - Run the coverage job on ubuntu-24.04, and only on PHP 8.3 (the old include applied report: true to every job) - Bump actions/checkout to v7 and codecov/codecov-action to v7 (cherry picked from commit 7ffe1aa) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1ad0a51 commit 8cdafef

5 files changed

Lines changed: 40 additions & 5 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: 7 additions & 4 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:
1010
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ QueryPath Changelog
44
# Unreleased changes
55

66
- 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

‎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)