Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid HTML test fails in some environments #29

Open
cameron1729 opened this issue Oct 17, 2023 · 0 comments
Open

Invalid HTML test fails in some environments #29

cameron1729 opened this issue Oct 17, 2023 · 0 comments

Comments

@cameron1729
Copy link

cameron1729 commented Oct 17, 2023

~/P/m/stable_401 ❯❯❯ ./vendor/bin/phpunit --testsuite=block_course_contents_testsuite                                                   MOODLE_401_STABLE ✭ ◼
Moodle 4.1.6+ (Build: 20231013), d188d58ce93badf7cb8d1b2a99b2ad00eb62c681
Php: 7.4.33, pgsql: 12.11 (Ubuntu 12.11-0ubuntu0.20.04.1), OS: Linux 5.15.0-86-generic x86_64
PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

.F.........                                                       11 / 11 (100%)

Time: 00:00.139, Memory: 64.50 MB

There was 1 failure:

1) block_course_contents\autotitle_test::test_extract_title with data set "Invalid HTML" ('</span>Hello<<h1>', 'Hello')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Hello'
+'Hello<'

Should be related to libxml version or something like that. I have:

~/P/m/stable_401 ❯❯❯ php -i | grep libxml
libxml Version => 2.9.14
libxml
libxml2 Version => 2.9.14
libxslt compiled against libxml Version => 2.9.13

And this script:

<?php

$summary = '</span>asd<<h1>';

$dom = new \DOMDocument();
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $summary);

echo LIBXML_DOTTED_VERSION;
echo "\n";

foreach ($dom->childNodes as $child) {
    echo $child->textContent;
    echo "\n";
}

Produces this output:

~ ❯❯❯ php test.php
PHP Warning:  DOMDocument::loadHTML(): Unexpected end tag : span in Entity, line: 1 in /home/cameronball/test.php on line 6
PHP Stack trace:
PHP   1. {main}() /home/cameronball/test.php:0
PHP   2. DOMDocument->loadHTML($source = '<?xml encoding="utf-8" ?></span>asd<<h1>') /home/cameronball/test.php:6
2.9.14

encoding="utf-8" ?
asd<

But on 3v4l the output is different: https://3v4l.org/LONuB (it produces just "asd" without the "<"). So seems like the behaviour is different in newer libxml (or even something else) potentially. See also:

I'm not sure this should even be tested. It's difficult to make calls on expected behavior when parsing invalid XML. Really what the test needs to assert is that there is no output produced by warnings - not assert what the value of the parsed invalid XML is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant