mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-02 12:51:53 +00:00
feat: add directive for removing blank nodes (#404)
This commit is contained in:
parent
4828fdf45a
commit
c9d60c96d7
File diff suppressed because one or more lines are too long
@ -0,0 +1,10 @@
|
|||||||
|
Core.RemoveBlanks
|
||||||
|
TYPE: bool
|
||||||
|
DEFAULT: false
|
||||||
|
VERSION: 4.18
|
||||||
|
--DESCRIPTION--
|
||||||
|
<p>
|
||||||
|
If set to true, blank nodes will be removed. This can be useful for maintaining
|
||||||
|
backwards compatibility when upgrading from previous versions of PHP.
|
||||||
|
</p>
|
||||||
|
--# vim: et sw=4 sts=4
|
@ -72,6 +72,9 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
|||||||
if ($config->get('Core.AllowParseManyTags') && defined('LIBXML_PARSEHUGE')) {
|
if ($config->get('Core.AllowParseManyTags') && defined('LIBXML_PARSEHUGE')) {
|
||||||
$options |= LIBXML_PARSEHUGE;
|
$options |= LIBXML_PARSEHUGE;
|
||||||
}
|
}
|
||||||
|
if ($config->get('Core.RemoveBlanks') && defined('LIBXML_NOBLANKS')) {
|
||||||
|
$options |= LIBXML_NOBLANKS;
|
||||||
|
}
|
||||||
|
|
||||||
set_error_handler(array($this, 'muteErrorHandler'));
|
set_error_handler(array($this, 'muteErrorHandler'));
|
||||||
// loadHTML() fails on PHP 5.3 when second parameter is given
|
// loadHTML() fails on PHP 5.3 when second parameter is given
|
||||||
|
@ -54,5 +54,6 @@ if (strtolower($GLOBALS['PHORUM']['DATA']['CHARSET']) !== 'utf-8') {
|
|||||||
$config->set('Core.EscapeNonASCIICharacters', true);
|
$config->set('Core.EscapeNonASCIICharacters', true);
|
||||||
}
|
}
|
||||||
$config->set('Core.AllowParseManyTags', false);
|
$config->set('Core.AllowParseManyTags', false);
|
||||||
|
$config->set('Core.RemoveBlanks', false);
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
// vim: et sw=4 sts=4
|
||||||
|
10
tests/HTMLPurifier/FixtureData/RemoveBlankTestCaseInput.html
Normal file
10
tests/HTMLPurifier/FixtureData/RemoveBlankTestCaseInput.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<table>
|
||||||
|
<caption>
|
||||||
|
Cool Table
|
||||||
|
</caption>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
Element 1
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
@ -0,0 +1,7 @@
|
|||||||
|
<table><caption>
|
||||||
|
Cool Table
|
||||||
|
</caption>
|
||||||
|
<tr><td>
|
||||||
|
Element 1
|
||||||
|
</td>
|
||||||
|
</tr></table>
|
@ -399,6 +399,19 @@ a[href|title]
|
|||||||
$this->assertIdentical($input, $output);
|
$this->assertIdentical($input, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_removeBlanks()
|
||||||
|
{
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('Core.RemoveBlanks', true);
|
||||||
|
|
||||||
|
$input = file_get_contents(__DIR__ . '/FixtureData/RemoveBlankTestCaseInput.html');
|
||||||
|
$expected = file_get_contents(__DIR__ . '/FixtureData/RemoveBlankTestCaseOutput.html');
|
||||||
|
|
||||||
|
$purifier = new HTMLPurifier($config);
|
||||||
|
$actual = $purifier->purify($input);
|
||||||
|
$this->assertIdentical($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
// vim: et sw=4 sts=4
|
||||||
|
Loading…
Reference in New Issue
Block a user