diff --git a/library/HTMLPurifier/AttrDef/CSS/Ratio.php b/library/HTMLPurifier/AttrDef/CSS/Ratio.php
new file mode 100644
index 000000000..e08e2c496
--- /dev/null
+++ b/library/HTMLPurifier/AttrDef/CSS/Ratio.php
@@ -0,0 +1,46 @@
+parseCDATA($ratio);
+
+ $parts = explode('/', $ratio, 2);
+ $length = count($parts);
+
+ if ($length < 1 || $length > 2) {
+ return false;
+ }
+
+ $num = new \HTMLPurifier_AttrDef_CSS_Number();
+
+ if ($length === 1) {
+ return $num->validate($parts[0], $config, $context);
+ }
+
+ $num1 = $num->validate($parts[0], $config, $context);
+ $num2 = $num->validate($parts[1], $config, $context);
+
+ if ($num1 === false || $num2 === false) {
+ return false;
+ }
+
+ return $num1 . '/' . $num2;
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php
index 1bc419c53..09321fd25 100644
--- a/library/HTMLPurifier/CSSDefinition.php
+++ b/library/HTMLPurifier/CSSDefinition.php
@@ -304,6 +304,13 @@ protected function doSetup($config)
$trusted_max_wh
);
+ $this->info['aspect-ratio'] = new HTMLPurifier_AttrDef_CSS_Multiple(
+ new HTMLPurifier_AttrDef_CSS_Composite([
+ new HTMLPurifier_AttrDef_CSS_Ratio(),
+ new HTMLPurifier_AttrDef_Enum(['auto']),
+ ])
+ );
+
// text-decoration and related shorthands
$this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration();
diff --git a/tests/HTMLPurifier/AttrDef/CSS/RatioTest.php b/tests/HTMLPurifier/AttrDef/CSS/RatioTest.php
new file mode 100644
index 000000000..f1d27af5a
--- /dev/null
+++ b/tests/HTMLPurifier/AttrDef/CSS/RatioTest.php
@@ -0,0 +1,24 @@
+def = new HTMLPurifier_AttrDef_CSS_Ratio();
+
+ $this->assertDef('1/2');
+ $this->assertDef('1 / 2', '1/2');
+ $this->assertDef('1');
+ $this->assertDef('1/0');
+ $this->assertDef('0/1');
+
+ $this->assertDef('1/2/3', false);
+ $this->assertDef('/2/3', false);
+ $this->assertDef('/12', false);
+ $this->assertDef('1/', false);
+ $this->assertDef('asdf', false);
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php
index 2367c187f..cff044ec1 100644
--- a/tests/HTMLPurifier/AttrDef/CSSTest.php
+++ b/tests/HTMLPurifier/AttrDef/CSSTest.php
@@ -72,6 +72,10 @@ public function test()
$this->assertDef('min-width:50rem;');
$this->assertDef('min-width:50vw;');
$this->assertDef('min-width:-50vw;', false);
+ $this->assertDef('aspect-ratio:16/9;');
+ $this->assertDef('aspect-ratio:auto;');
+ $this->assertDef('aspect-ratio:16/9 auto;');
+ $this->assertDef('aspect-ratio:auto 16/9;');
$this->assertDef('text-decoration:underline;');
$this->assertDef('text-decoration-line:overline;');
$this->assertDef('text-decoration-style:dashed;');