Open babaduk47 opened 1 week ago
The order in which styles are applied is affected by the class name:
I've provided 2 examples that demonstrate this
Example 1:
<div class="text-b text-a">Foo</div>
Expected output:
Actual output:
Since text-decoration: line-through was applied, this means that text-a was applied first and then text-b
text-decoration: line-through
text-a
text-b
But if we rename the text-a class to text-c, we will get the expected result
text-c
Example 2:
<div class="text-b text-c">Foo</div>
It seems that the order in which classes are applied is affected by alphabetical order.
Note: If you render html in a browser, this problem does not occur.
v8.2.4
PHP 7.4.33 (cli) (built: Sep 27 2024 12:56:02) ( NTS ) and PHP 8.3.12 (cli) (built: Sep 24 2024 18:08:04) (NTS)
First testcase:
<?php require __DIR__ . '/vendor/autoload.php'; $mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => 'A4', ]); $html = <<<HTML <html lang="en"> <head> <title>Testcase</title> </head> <style> div {font-size: 108px;} .text-b { background-color: black; text-transform: uppercase; color: green; } .text-a { background-color: blue; color: red; text-decoration: line-through; } </style> <body> <div id="root"> <div class="text-b text-a">Foo</div> <hr> <div class="text-a text-b">Bar</div> </div> </body> </html> HTML; $mpdf->WriteHTML($html); $mpdf->Output('test_b_a.pdf', 'F');
Second testcase:
<?php require __DIR__ . '/vendor/autoload.php'; $mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => 'A4', ]); $html = <<<HTML <html lang="en"> <head> <title>Testcase</title> </head> <style> div {font-size: 108px;} .text-b { background-color: black; text-transform: uppercase; color: green; } .text-c { background-color: blue; color: red; text-decoration: line-through; } </style> <body> <div id="root"> <div class="text-b text-c">Foo</div> <hr> <div class="text-c text-b">Bar</div> </div> </body> </html> HTML; $mpdf->WriteHTML($html); $mpdf->Output('test_b_c.pdf', 'F');
It looks like the problem is in Arrays::allUniqueSortedCombinations:41 - the order of classes changes there
Arrays::allUniqueSortedCombinations:41
Related https://github.com/mpdf/mpdf/issues/1753
Guidelines
Description of the bug
The order in which styles are applied is affected by the class name:
I've provided 2 examples that demonstrate this
Example 1:
<div class="text-b text-a">Foo</div>
Expected output:
Actual output:
Since
text-decoration: line-through
was applied, this means thattext-a
was applied first and thentext-b
But if we rename the
text-a
class totext-c
, we will get the expected resultExample 2:
<div class="text-b text-c">Foo</div>
Actual output:
It seems that the order in which classes are applied is affected by alphabetical order.
mPDF version
v8.2.4
PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)
PHP 7.4.33 (cli) (built: Sep 27 2024 12:56:02) ( NTS ) and PHP 8.3.12 (cli) (built: Sep 24 2024 18:08:04) (NTS)
Reproducible PHP+CSS+HTML snippet suffering by the error
First testcase:
Second testcase: