diff --git a/NEWS b/NEWS index 76930cd7..a6d7aec6 100644 --- a/NEWS +++ b/NEWS @@ -5,7 +5,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fixed broken numeric entity conversion - Malformed UTF-8 and non-SGML character detection and cleaning implemented - API documentation completed -- Shorthand CSS properties implemented: font +- Shorthand CSS properties implemented: font, border - Basic color keywords translated into hexadecimal values 1.0.0beta, released 2006-08-16 diff --git a/TODO b/TODO index 9d3cc436..afa780b9 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ Core: - Finish table and shorthand CSS attributes - border-collapse, caption-side, empty-cells, table-layout, vertical-align - background (and friends) - - border, border-* - list-style - Implement all non-essential attribute transforms - Microsoft Word HTML cleaning diff --git a/docs/progress.html b/docs/progress.html index 1b1bb57d..22204377 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -135,11 +135,11 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} Standard background-colorCOMPOSITE(<color>, transparent) backgroundSHORTHAND -borderSHORTHAND, MULTIPLE +borderSHORTHAND, MULTIPLE border-colorMULTIPLE border-styleMULTIPLE border-widthMULTIPLE -border-*SHORTHAND +border-*SHORTHAND border-*-colorCOMPOSITE(<color>, transparent) border-*-styleENUM(none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset) diff --git a/library/HTMLPurifier/AttrDef/Border.php b/library/HTMLPurifier/AttrDef/Border.php new file mode 100644 index 00000000..df81f31e --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Border.php @@ -0,0 +1,45 @@ +info['border-width'] = $def->info['border-width']; + $this->info['border-style'] = $def->info['border-style']; + $this->info['border-top-color'] = $def->info['border-top-color']; + } + + function validate($string, $config, &$context) { + $string = $this->parseCDATA($string); + // we specifically will not support rgb() syntax with spaces + $bits = explode(' ', $string); + $done = array(); // segments we've finished + $ret = ''; // return value + foreach ($bits as $bit) { + foreach ($this->info as $propname => $validator) { + if (isset($done[$propname])) continue; + $r = $validator->validate($bit, $config, &$context); + if ($r !== false) { + $ret .= $r . ' '; + $done[$propname] = true; + break; + } + } + } + return rtrim($ret); + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 9517fdfa..a46b13c6 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -9,6 +9,7 @@ require_once 'HTMLPurifier/AttrDef/Multiple.php'; require_once 'HTMLPurifier/AttrDef/TextDecoration.php'; require_once 'HTMLPurifier/AttrDef/FontFamily.php'; require_once 'HTMLPurifier/AttrDef/Font.php'; +require_once 'HTMLPurifier/AttrDef/Border.php'; /** * Defines allowed CSS attributes and what their values are. @@ -170,6 +171,13 @@ class HTMLPurifier_CSSDefinition // a CSSDefinition object $this->info['font'] = new HTMLPurifier_AttrDef_Font(); + // same here + $this->info['border'] = + $this->info['border-bottom'] = + $this->info['border-top'] = + $this->info['border-left'] = + $this->info['border-right'] = new HTMLPurifier_AttrDef_Border(); + } } diff --git a/tests/HTMLPurifier/AttrDef/BorderTest.php b/tests/HTMLPurifier/AttrDef/BorderTest.php new file mode 100644 index 00000000..54d64457 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/BorderTest.php @@ -0,0 +1,21 @@ +def = new HTMLPurifier_AttrDef_Border(); + + $this->assertDef('thick solid red', 'thick solid #F00'); + $this->assertDef('thick solid'); + $this->assertDef('solid red', 'solid #F00'); + $this->assertDef('1px solid #000'); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index efe69873..3806826f 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -60,7 +60,9 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('text-decoration:underline;'); $this->assertDef('font-family:sans-serif;'); $this->assertDef('font-family:Gill, \'Times New Roman\', sans-serif;'); - //$this->assertDef('font:12px serif;'); + $this->assertDef('font:12px serif;'); + $this->assertDef('border:1px solid #000;'); + $this->assertDef('border-bottom:2em double #FF00FA;'); // duplicates $this->assertDef('text-align:right;text-align:left;', diff --git a/tests/index.php b/tests/index.php index 7ea6cf94..1198b096 100644 --- a/tests/index.php +++ b/tests/index.php @@ -76,6 +76,7 @@ $test_files[] = 'AttrDef/HostTest.php'; $test_files[] = 'AttrDef/IPv4Test.php'; $test_files[] = 'AttrDef/IPv6Test.php'; $test_files[] = 'AttrDef/FontTest.php'; +$test_files[] = 'AttrDef/BorderTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php';