Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ on: [ pull_request ]

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

name: PHP ${{ matrix.php-versions }} PHPUnit Test
steps:
- name: Checkout repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -41,7 +44,7 @@ jobs:

- name: Check Code Coverage
if: ${{ matrix.report }}
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v7
with:
directory: ./coverage/
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ QueryPath Changelog

# Unreleased changes

-
- Add support for PHP 8.6
- 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

# 4.1.0

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gravitypdf/querypath",
"type": "library",
"description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.5 support",
"description": "PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP 7.0 to 8.6 support",
"homepage": "https://github.com/gravitypdf/querypath",
"license": "MIT",
"keywords": [
Expand All @@ -23,7 +23,7 @@
}
],
"require": {
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0",
"masterminds/html5": "^2.0"
},
"autoload": {
Expand Down
2 changes: 2 additions & 0 deletions tests/QueryPath/DOMQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function testFailedHTTPLoadWithContext()

public function testFailedParseHTMLElement()
{
$this->requireLegacyHtmlParser();

$this->expectException(ParseException::class);

try {
Expand Down
29 changes: 29 additions & 0 deletions tests/QueryPath/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,33 @@ class TestCase extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
{
public const DATA_FILE_XML = 'tests/data.xml';
public const DATA_FILE_HTML = 'tests/data.html';

/**
* Whether libxml's HTML parser follows HTML5, as it does from 2.14.
*
* Such a parser reads `<?...>` as a comment rather than a processing instruction, and reports no
* parse errors. Probed rather than read from LIBXML_VERSION, which is the version PHP was built
* against, not necessarily the one it runs with.
*
* @return bool
*/
protected static function libxmlParsesHtmlAsHtml5(): bool
{
static $html5;

if ($html5 === null) {
$document = new \DOMDocument();
@$document->loadHTML('<p><?x y?></p>');
$html5 = ! $document->getElementsByTagName('p')->item(0)->firstChild instanceof \DOMProcessingInstruction;
}

return $html5;
}

protected function requireLegacyHtmlParser()
{
if (self::libxmlParsesHtmlAsHtml5()) {
$this->markTestSkipped('libxml ' . LIBXML_DOTTED_VERSION . ' parses HTML as HTML5.');
}
}
}