diff --git a/NEWS b/NEWS
index 476d7d37..b08c431e 100644
--- a/NEWS
+++ b/NEWS
@@ -12,13 +12,12 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
1.4.0, unknown release date
! Implemented list-style-image, URIs now allowed in list-style
! Implemented background-image, background-repeat, background-attachment
- and background-position CSS properties. Background shorthand property is
- currently equivalent to background-image and does not support the
- new properties.
+ and background-position CSS properties. Shorthand property background
+ supports all of these properties.
! Configuration documentation looks nicer
-! Added smoketest 'all.php', which loads all other smoketests via frames
! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode
characters while %Core.Encoding is set to a non-UTF-8 encoding.
+. Added smoketest 'all.php', which loads all other smoketests via frames
. Implemented AttrDef_CSSURI for url(http://google.com) style declarations
. Added convenient single test selector form on test runner
diff --git a/docs/dev-progress.html b/docs/dev-progress.html
index 73dcd36e..87ac704a 100644
--- a/docs/dev-progress.html
+++ b/docs/dev-progress.html
@@ -60,7 +60,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
Standard |
background-color | COMPOSITE(<color>, transparent) |
-background | SHORTHAND, currently alias for background-color |
+background | SHORTHAND, currently alias for background-color |
border | SHORTHAND, MULTIPLE |
border-color | MULTIPLE |
border-style | MULTIPLE |
@@ -231,7 +231,7 @@ Mozilla on inside and needs -moz-outline, no IE support.
CSS |
-style | All | Not all properties may be implemented, parser is good though. |
+style | All | Parser is reasonably functional. Status here doesn't count individual properties. |
diff --git a/library/HTMLPurifier/AttrDef/Background.php b/library/HTMLPurifier/AttrDef/Background.php
new file mode 100644
index 00000000..1db3f88d
--- /dev/null
+++ b/library/HTMLPurifier/AttrDef/Background.php
@@ -0,0 +1,87 @@
+getCSSDefinition();
+ $this->info['background-color'] = $def->info['background-color'];
+ $this->info['background-image'] = $def->info['background-image'];
+ $this->info['background-repeat'] = $def->info['background-repeat'];
+ $this->info['background-attachment'] = $def->info['background-attachment'];
+ $this->info['background-position'] = $def->info['background-position'];
+ }
+
+ function validate($string, $config, &$context) {
+
+ // regular pre-processing
+ $string = $this->parseCDATA($string);
+ if ($string === '') return false;
+
+ // assumes URI doesn't have spaces in it
+ $bits = explode(' ', strtolower($string)); // bits to process
+
+ $caught = array();
+ $caught['color'] = false;
+ $caught['image'] = false;
+ $caught['repeat'] = false;
+ $caught['attachment'] = false;
+ $caught['position'] = false;
+
+ $i = 0; // number of catches
+ $none = false;
+
+ foreach ($bits as $bit) {
+ if ($bit === '') continue;
+ foreach ($caught as $key => $status) {
+ if ($key != 'position') {
+ if ($status !== false) continue;
+ $r = $this->info['background-' . $key]->validate($bit, $config, $context);
+ } else {
+ $r = $bit;
+ }
+ if ($r === false) continue;
+ if ($key == 'position') {
+ if ($caught[$key] === false) $caught[$key] = '';
+ $caught[$key] .= $r . ' ';
+ } else {
+ $caught[$key] = $r;
+ }
+ $i++;
+ break;
+ }
+ }
+
+ if (!$i) return false;
+ if ($caught['position'] !== false) {
+ $caught['position'] = $this->info['background-position']->
+ validate($caught['position'], $config, $context);
+ }
+
+ $ret = array();
+ foreach ($caught as $value) {
+ if ($value === false) continue;
+ $ret[] = $value;
+ }
+
+ if (empty($ret)) return false;
+ return implode(' ', $ret);
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/library/HTMLPurifier/AttrDef/ListStyle.php b/library/HTMLPurifier/AttrDef/ListStyle.php
index b866798c..b09ee354 100644
--- a/library/HTMLPurifier/AttrDef/ListStyle.php
+++ b/library/HTMLPurifier/AttrDef/ListStyle.php
@@ -53,6 +53,7 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef
}
$caught[$key] = $r;
$i++;
+ break;
}
}
diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php
index cb97b6c3..0bbe8af5 100644
--- a/library/HTMLPurifier/CSSDefinition.php
+++ b/library/HTMLPurifier/CSSDefinition.php
@@ -12,6 +12,8 @@ require_once 'HTMLPurifier/AttrDef/Font.php';
require_once 'HTMLPurifier/AttrDef/Border.php';
require_once 'HTMLPurifier/AttrDef/ListStyle.php';
require_once 'HTMLPurifier/AttrDef/CSSURI.php';
+require_once 'HTMLPurifier/AttrDef/BackgroundPosition.php';
+require_once 'HTMLPurifier/AttrDef/Background.php';
/**
* Defines allowed CSS attributes and what their values are.
@@ -81,9 +83,6 @@ class HTMLPurifier_CSSDefinition
);
$this->info['background-position'] = new HTMLPurifier_AttrDef_BackgroundPosition();
- // pending its own validator as a shorthand
- $this->info['background'] =
-
$border_color =
$this->info['border-top-color'] =
$this->info['border-bottom-color'] =
@@ -94,6 +93,8 @@ class HTMLPurifier_CSSDefinition
new HTMLPurifier_AttrDef_Color()
));
+ $this->info['background'] = new HTMLPurifier_AttrDef_Background($config);
+
$this->info['border-color'] = new HTMLPurifier_AttrDef_Multiple($border_color);
$border_width =
diff --git a/tests/HTMLPurifier/AttrDef/BackgroundTest.php b/tests/HTMLPurifier/AttrDef/BackgroundTest.php
new file mode 100644
index 00000000..69b3c1ba
--- /dev/null
+++ b/tests/HTMLPurifier/AttrDef/BackgroundTest.php
@@ -0,0 +1,21 @@
+def = new HTMLPurifier_AttrDef_Background(HTMLPurifier_Config::createDefault());
+
+ $valid = '#333 url(chess.png) repeat fixed 50% top';
+ $this->assertDef($valid);
+ $this->assertDef('url("chess.png") #333 50% top repeat fixed', $valid);
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php
index e63153d0..9371f788 100644
--- a/tests/HTMLPurifier/AttrDef/CSSTest.php
+++ b/tests/HTMLPurifier/AttrDef/CSSTest.php
@@ -25,7 +25,7 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('text-transform:capitalize;');
$this->assertDef('background-color:rgb(0,0,255);');
$this->assertDef('background-color:transparent;');
- $this->assertDef('background:#FF9;');
+ $this->assertDef('background:#333 url(chess.png) repeat fixed 50% top;');
$this->assertDef('color:#F00;');
$this->assertDef('border-top-color:#F00;');
$this->assertDef('border-color:#F00 #FF0;');
diff --git a/tests/test_files.php b/tests/test_files.php
index 378458f5..ab83ec47 100644
--- a/tests/test_files.php
+++ b/tests/test_files.php
@@ -50,6 +50,7 @@ $test_files[] = 'AttrDef/ListStyleTest.php';
$test_files[] = 'AttrDef/Email/SimpleCheckTest.php';
$test_files[] = 'AttrDef/CSSURITest.php';
$test_files[] = 'AttrDef/BackgroundPositionTest.php';
+$test_files[] = 'AttrDef/BackgroundTest.php';
$test_files[] = 'IDAccumulatorTest.php';
$test_files[] = 'TagTransformTest.php';
$test_files[] = 'AttrTransform/LangTest.php';