From cbb492c52ced3ffaa387e91e055cd4b318f1d076 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 6 Dec 2006 22:12:44 +0000 Subject: [PATCH] [1.3.1] Fixed bug in RemoveInvalidImg code that caused all images to be dropped git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@599 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 2 +- .../HTMLPurifier/Strategy/RemoveForeignElements.php | 11 +++++++---- .../Strategy/RemoveForeignElementsTest.php | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 6c26835f..aef3b2e4 100644 --- a/NEWS +++ b/NEWS @@ -13,8 +13,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier (major feature release) 1.3.1, unknown release date -(security/bugfix/minor feature release) ! Added HTMLPurifier.func.php stub for a convenient function to call the library +. Fixed bug in RemoveInvalidImg code that caused all images to be dropped 1.3.0, released 2006-11-26 # Invalid images are now removed, rather than replaced with a dud diff --git a/library/HTMLPurifier/Strategy/RemoveForeignElements.php b/library/HTMLPurifier/Strategy/RemoveForeignElements.php index b06c864b..ec23b101 100644 --- a/library/HTMLPurifier/Strategy/RemoveForeignElements.php +++ b/library/HTMLPurifier/Strategy/RemoveForeignElements.php @@ -38,16 +38,19 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy // hard-coded image special case, pre-emptively drop // if not available. Probably not abstract-able if ( $token->name == 'img' ) { - if (!isset($token->attr['src'])) continue; + if (!isset($token->attributes['src'])) { + continue; + } if (!isset($definition->info['img']->attr['src'])) { continue; } - $token->attr['src'] = + $token->attributes['src'] = $definition-> info['img']-> attr['src']-> - validate($token->attr['src']); - if ($token->attr['src'] === false) continue; + validate($token->attributes['src'], + $config, $context); + if ($token->attributes['src'] === false) continue; } } elseif ( diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php index 0318a85a..e2227705 100644 --- a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php +++ b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php @@ -42,12 +42,15 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest ' Warning!' ); - // test removal of img tag + // test removal of invalid img tag $this->assertResult( '', '' ); + // test preservation of valid img tag + $this->assertResult(''); + } }