Skip to content

Commit 92a6b75

Browse files
jakejackson1claude
andcommitted
Keep the -webkit- and -o- prefix of a gradient in the background shorthand
Since #577, a -webkit- or -o- gradient is told apart from an unprefixed one by its prefix, and keeps the legacy angles and start side. The background shorthand parser dropped every prefix but -moz-, so `background: -webkit-linear-gradient(left, …)` was read as an unprefixed gradient. It now keeps -moz-, -webkit- and -o-, and still drops any other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1a0e1da commit 92a6b75

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎src/Css/NormalizeProperties.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ private function parseBackgroundLayer(array $components)
512512
if (preg_match('/^url\(\s*([\'"]?)(.*)\1\s*\)$/is', $components[$i], $m)) {
513513
$kind = 'i';
514514
$value = $m[2];
515-
} elseif (preg_match('/^(?:-(?!moz-)[a-z]+-)?((-moz-)?(repeating-)?(linear|radial)-gradient\(.*\))$/is', $components[$i], $m)) {
516-
// Drops a vendor prefix other than -moz-, which the gradient parser reads
515+
} elseif (preg_match('/^(?:-(?!(?:moz|webkit|o)-)[a-z]+-)?((-moz-|-webkit-|-o-)?(repeating-)?(linear|radial)-gradient\(.*\))$/is', $components[$i], $m)) {
516+
// Drops a vendor prefix other than -moz-, -webkit- and -o-, which the gradient parser reads for their legacy angles
517517
$kind = 'i';
518518
$value = $m[1];
519519
} elseif ($keyword === 'none') {

‎tests/Mpdf/Css/NormalizePropertiesTest.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,13 @@ public function providerBackground()
367367
'inherit',
368368
['BACKGROUND-COLOR' => 'transparent', 'BACKGROUND-IMAGE' => ''],
369369
],
370-
'a -webkit- gradient' => [
370+
'a -webkit- gradient keeps its prefix for its legacy angles' => [
371371
'-webkit-linear-gradient(left, red, blue)',
372-
['BACKGROUND-COLOR' => 'transparent', 'BACKGROUND-IMAGE' => 'linear-gradient(left, red, blue)'],
372+
['BACKGROUND-COLOR' => 'transparent', 'BACKGROUND-IMAGE' => '-webkit-linear-gradient(left, red, blue)'],
373+
],
374+
'a gradient with another vendor prefix' => [
375+
'-ms-linear-gradient(to right, red, blue)',
376+
['BACKGROUND-COLOR' => 'transparent', 'BACKGROUND-IMAGE' => 'linear-gradient(to right, red, blue)'],
373377
],
374378
'a -moz- gradient' => [
375379
'-moz-linear-gradient(left, red, blue)',

0 commit comments

Comments
 (0)