mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
Add support for proprietary "background" attribute in table elements.
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
parent
6a06b92f0c
commit
d0fdcc103e
2
NEWS
2
NEWS
@ -34,6 +34,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
improved.
|
improved.
|
||||||
! Experimental implementation of forms for %HTML.Trusted
|
! Experimental implementation of forms for %HTML.Trusted
|
||||||
! Track column numbers when maintain line numbers is on
|
! Track column numbers when maintain line numbers is on
|
||||||
|
! Proprietary 'background' attribute on table-related elements converted into
|
||||||
|
corresponding CSS. Thanks Fusemail for sponsoring this feature!
|
||||||
- Fix two bugs in %URI.MakeAbsolute; one involving empty paths in base URLs,
|
- Fix two bugs in %URI.MakeAbsolute; one involving empty paths in base URLs,
|
||||||
the other involving an undefined $is_folder error.
|
the other involving an undefined $is_folder error.
|
||||||
- Throw error when %Core.Encoding is set to a spurious value. Previously,
|
- Throw error when %Core.Encoding is set to a spurious value. Previously,
|
||||||
|
@ -109,6 +109,7 @@ require 'HTMLPurifier/AttrDef/URI/Host.php';
|
|||||||
require 'HTMLPurifier/AttrDef/URI/IPv4.php';
|
require 'HTMLPurifier/AttrDef/URI/IPv4.php';
|
||||||
require 'HTMLPurifier/AttrDef/URI/IPv6.php';
|
require 'HTMLPurifier/AttrDef/URI/IPv6.php';
|
||||||
require 'HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php';
|
require 'HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php';
|
||||||
|
require 'HTMLPurifier/AttrTransform/Background.php';
|
||||||
require 'HTMLPurifier/AttrTransform/BdoDir.php';
|
require 'HTMLPurifier/AttrTransform/BdoDir.php';
|
||||||
require 'HTMLPurifier/AttrTransform/BgColor.php';
|
require 'HTMLPurifier/AttrTransform/BgColor.php';
|
||||||
require 'HTMLPurifier/AttrTransform/BoolToCSS.php';
|
require 'HTMLPurifier/AttrTransform/BoolToCSS.php';
|
||||||
|
@ -103,6 +103,7 @@ require_once $__dir . '/HTMLPurifier/AttrDef/URI/Host.php';
|
|||||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv4.php';
|
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv4.php';
|
||||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv6.php';
|
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv6.php';
|
||||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php';
|
require_once $__dir . '/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php';
|
||||||
|
require_once $__dir . '/HTMLPurifier/AttrTransform/Background.php';
|
||||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BdoDir.php';
|
require_once $__dir . '/HTMLPurifier/AttrTransform/BdoDir.php';
|
||||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BgColor.php';
|
require_once $__dir . '/HTMLPurifier/AttrTransform/BgColor.php';
|
||||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BoolToCSS.php';
|
require_once $__dir . '/HTMLPurifier/AttrTransform/BoolToCSS.php';
|
||||||
|
22
library/HTMLPurifier/AttrTransform/Background.php
Normal file
22
library/HTMLPurifier/AttrTransform/Background.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes proprietary background attribute to CSS.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_Background extends HTMLPurifier_AttrTransform {
|
||||||
|
|
||||||
|
public function transform($attr, $config, $context) {
|
||||||
|
|
||||||
|
if (!isset($attr['background'])) return $attr;
|
||||||
|
|
||||||
|
$background = $this->confiscateAttr($attr, 'background');
|
||||||
|
// some validation should happen here
|
||||||
|
|
||||||
|
$this->prependCSS($attr, "background-image:url($background);");
|
||||||
|
|
||||||
|
return $attr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,15 @@ class HTMLPurifier_HTMLModule_Tidy_Proprietary extends HTMLPurifier_HTMLModule_T
|
|||||||
public $defaultLevel = 'light';
|
public $defaultLevel = 'light';
|
||||||
|
|
||||||
public function makeFixes() {
|
public function makeFixes() {
|
||||||
return array();
|
$r = array();
|
||||||
|
$r['table@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['td@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['th@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['tr@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['thead@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['tfoot@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
$r['tbody@background'] = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
39
tests/HTMLPurifier/AttrTransform/BackgroundTest.php
Normal file
39
tests/HTMLPurifier/AttrTransform/BackgroundTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransformHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->obj = new HTMLPurifier_AttrTransform_Background();
|
||||||
|
}
|
||||||
|
|
||||||
|
function testEmptyInput() {
|
||||||
|
$this->assertResult( array() );
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBasicTransform() {
|
||||||
|
$this->assertResult(
|
||||||
|
array('background' => 'logo.png'),
|
||||||
|
array('style' => 'background-image:url(logo.png);')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPrependNewCSS() {
|
||||||
|
$this->assertResult(
|
||||||
|
array('background' => 'logo.png', 'style' => 'font-weight:bold'),
|
||||||
|
array('style' => 'background-image:url(logo.png);font-weight:bold')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLenientTreatmentOfInvalidInput() {
|
||||||
|
// notice that we rely on the CSS validator later to fix this invalid
|
||||||
|
// stuff
|
||||||
|
$this->assertResult(
|
||||||
|
array('background' => 'logo.png);foo:('),
|
||||||
|
array('style' => 'background-image:url(logo.png);foo:();')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
4
tests/HTMLPurifier/HTMLT/tidy-background.htmlt
Normal file
4
tests/HTMLPurifier/HTMLT/tidy-background.htmlt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
--HTML--
|
||||||
|
<table background="logo.png"><tr><td>asdf</td></tr></table>
|
||||||
|
--EXPECT--
|
||||||
|
<table style="background-image:url(logo.png);"><tr><td>asdf</td></tr></table>
|
Loading…
Reference in New Issue
Block a user