Skip to content

Commit

Permalink
CSS: Add "background-size" tag support (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Václav Smítal committed Apr 22, 2021
1 parent 1354e7e commit 6f9aac9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/HTMLPurifier/AttrDef/CSS/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct($config)
$this->info['background-repeat'] = $def->info['background-repeat'];
$this->info['background-attachment'] = $def->info['background-attachment'];
$this->info['background-position'] = $def->info['background-position'];
$this->info['background-size'] = $def->info['background-size'];
}

/**
Expand Down Expand Up @@ -53,6 +54,7 @@ public function validate($string, $config, $context)
$caught['repeat'] = false;
$caught['attachment'] = false;
$caught['position'] = false;
$caught['size'] = false;

$i = 0; // number of catches

Expand Down
16 changes: 16 additions & 0 deletions library/HTMLPurifier/CSSDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ protected function doSetup($config)
);
$this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();

$this->info['background-size'] = new HTMLPurifier_AttrDef_CSS_Composite(
array(
new HTMLPurifier_AttrDef_Enum(
array(
'auto',
'cover',
'contain',
'initial',
'inherit',
)
),
new HTMLPurifier_AttrDef_CSS_Percentage(),
new HTMLPurifier_AttrDef_CSS_Length()
)
);

$border_color =
$this->info['border-top-color'] =
$this->info['border-bottom-color'] =
Expand Down
3 changes: 3 additions & 0 deletions tests/HTMLPurifier/AttrDef/CSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public function test()
$this->assertDef('background-repeat:repeat-y;');
$this->assertDef('background-attachment:fixed;');
$this->assertDef('background-position:left 90%;');
$this->assertDef('background-size:50%;');
$this->assertDef('background-size:cover;');
$this->assertDef('background-size:200px;');
$this->assertDef('border-spacing:1em;');
$this->assertDef('border-spacing:1em 2em;');
$this->assertDef('border-color: rgb(0, 0, 0) rgb(10,0,10)', 'border-color:rgb(0,0,0) rgb(10,0,10);');
Expand Down

0 comments on commit 6f9aac9

Please sign in to comment.