From 3166b8a10ffdf8c5154752688f232825211bb9d9 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 5 May 2010 15:08:57 -0400 Subject: [PATCH] Fix bug in background-position with center keyword. Signed-off-by: Edward Z. Yang --- NEWS | 1 + .../AttrDef/CSS/BackgroundPosition.php | 21 ++++++++++++------- .../AttrDef/CSS/BackgroundPositionTest.php | 10 ++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index b78cf391..a8d9bc45 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier 4.1.1, unknown release date - Emit an error for CollectErrors if a body is extracted +- Fix bug where in background-position for center keyword handling. 4.1.0, released 2010-04-26 ! Support proprietary height attribute on table element diff --git a/library/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php b/library/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php index 35df3985..fae82eae 100644 --- a/library/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php +++ b/library/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php @@ -59,7 +59,8 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef $keywords = array(); $keywords['h'] = false; // left, right $keywords['v'] = false; // top, bottom - $keywords['c'] = false; // center + $keywords['ch'] = false; // center (first word) + $keywords['cv'] = false; // center (second word) $measures = array(); $i = 0; @@ -79,6 +80,13 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef $lbit = ctype_lower($bit) ? $bit : strtolower($bit); if (isset($lookup[$lbit])) { $status = $lookup[$lbit]; + if ($status == 'c') { + if ($i == 0) { + $status = 'ch'; + } else { + $status = 'cv'; + } + } $keywords[$status] = $lbit; $i++; } @@ -101,20 +109,19 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef if (!$i) return false; // no valid values were caught - $ret = array(); // first keyword if ($keywords['h']) $ret[] = $keywords['h']; - elseif (count($measures)) $ret[] = array_shift($measures); - elseif ($keywords['c']) { - $ret[] = $keywords['c']; - $keywords['c'] = false; // prevent re-use: center = center center + elseif ($keywords['ch']) { + $ret[] = $keywords['ch']; + $keywords['cv'] = false; // prevent re-use: center = center center } + elseif (count($measures)) $ret[] = array_shift($measures); if ($keywords['v']) $ret[] = $keywords['v']; + elseif ($keywords['cv']) $ret[] = $keywords['cv']; elseif (count($measures)) $ret[] = array_shift($measures); - elseif ($keywords['c']) $ret[] = $keywords['c']; if (empty($ret)) return false; return implode(' ', $ret); diff --git a/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php b/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php index f5302c37..a216b267 100644 --- a/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php +++ b/tests/HTMLPurifier/AttrDef/CSS/BackgroundPositionTest.php @@ -28,13 +28,13 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrD // reordered due to internal impl details $this->assertDef('top left', 'left top'); - $this->assertDef('top center', 'center top'); + $this->assertDef('top center', 'top'); $this->assertDef('top right', 'right top'); - $this->assertDef('center left', 'left center'); - $this->assertDef('center center', 'center'); // two centers collide - $this->assertDef('center right', 'right center'); + $this->assertDef('center left', 'left'); + $this->assertDef('center center', 'center'); + $this->assertDef('center right', 'right'); $this->assertDef('bottom left', 'left bottom'); - $this->assertDef('bottom center', 'center bottom'); + $this->assertDef('bottom center', 'bottom'); $this->assertDef('bottom right', 'right bottom'); // more cases from the defined syntax