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

CSS: Add "background-size" tag support #289

Merged
merged 1 commit into from
Apr 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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