[pLog-svn] r7146 - in plog/branches/lifetype-1.2/class: data test/tests/data
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Wed Oct 26 17:45:36 EDT 2011
Author: jondaley
Date: 2011-10-26 17:45:36 -0400 (Wed, 26 Oct 2011)
New Revision: 7146
Modified:
plog/branches/lifetype-1.2/class/data/textfilter.class.php
plog/branches/lifetype-1.2/class/test/tests/data/textfilter_test.class.php
Log:
start using balance tags, to avoid problems like http://bugs.lifetype.net/view.php?id=1621. filterHTML should be a static function. Note that the current tests crashes balanceTags, which is probably why it was removed previously
Modified: plog/branches/lifetype-1.2/class/data/textfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/textfilter.class.php 2011-10-26 20:34:08 UTC (rev 7145)
+++ plog/branches/lifetype-1.2/class/data/textfilter.class.php 2011-10-26 21:45:36 UTC (rev 7146)
@@ -25,16 +25,11 @@
class TextFilter
{
- var $htmlAllowedTags;
-
/**
* Constructor.
*/
function TextFilter()
{
- lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
- $config =& Config::getConfig();
- $this->htmlAllowedTags = $config->getValue( "html_allowed_tags_in_comments" );
}
/**
@@ -64,9 +59,16 @@
*/
function filterHTML( $string )
{
- $tmp = strip_tags( $string, $this->htmlAllowedTags );
- // y luego eliminamos el javascript
- $filteredString = $this->filterJavaScript( $tmp );
+ static $htmlAllowedTags = "";
+ if(!$htmlAllowedTags){
+ lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+ $config =& Config::getConfig();
+ $htmlAllowedTags = $config->getValue( "html_allowed_tags_in_comments" );
+ }
+
+ $tmp = strip_tags( $string, $htmlAllowedTags );
+ $tmp = TextFilter::balanceTags($tmp);
+ $filteredString = TextFilter::filterJavaScript( $tmp );
return $filteredString;
}
@@ -82,7 +84,6 @@
function filterAllHTML( $string )
{
$tmp = strip_tags( $string );
- // y luego eliminamos el javascript
$filteredString = Textfilter::filterJavaScript( $tmp );
return( trim($filteredString));
@@ -291,7 +292,7 @@
* Added Cleaning Hooks
* 1.0 First Version
*/
- function balanceTags($text, $is_comment = 0)
+ function balanceTags($text)
{
$tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
@@ -472,7 +473,7 @@
/**
* xhtml-izes a string. It uses the KSes filter for the task as long as the configuration parameter
- * xhtml_converter_enabled is enabled. If xhtml_converter_aggreesive_mode_enabled is also enabled,
+ * xhtml_converter_enabled is enabled. If xhtml_converter_aggressive_mode_enabled is also enabled,
* KSes will be set into "aggressive" mode and it will try to fix even more problems with the XHTML
* markup (but it can also introduce more mistakes)
*
Modified: plog/branches/lifetype-1.2/class/test/tests/data/textfilter_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/data/textfilter_test.class.php 2011-10-26 20:34:08 UTC (rev 7145)
+++ plog/branches/lifetype-1.2/class/test/tests/data/textfilter_test.class.php 2011-10-26 21:45:36 UTC (rev 7146)
@@ -122,5 +122,36 @@
$this->assertEquals( $output, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $output )));
}
}
- }
+
+ /**
+ * tests the htmlDecode() method
+ */
+ function testHtmlFilter()
+ {
+ // array with strings and the expected result, the key is the
+ // input and the value is the expected output, add more if needed
+ $tests = Array(
+ " this is a plain text comment " => " this is a plain text comment ",
+ "some <a>html</a><b>is</b><h1>not</h1><p>allowed</p>" =>
+ "some <a>html</a><b>is</b>not<p>allowed</p>",
+ "non-html like < is ok" => "non-html like < is ok",
+ "non-html like > is ok" => "non-html like > is ok",
+ "Unclosed tags should be <i> closed" => "Unclosed tags should be <i> closed</i>",
+ "NULL tags <> should be removed?" => "NULL tags should be removed?",
+ "Empty tags < > should be not crash." => "Empty tags < > should be not crash.",
+ "Other HTML is not <h1> <p>allowed</p></h1>" => "Other HTML is not <p>allowed</p>",
+// "&" => "&",
+// "test" => "test",
+ );
+
+ foreach( $tests as $input => $output ) {
+ // check that the input is equal to the output after processing it with TextFilter::htmlDecode
+ $this->assertEquals( $output, TextFilter::filterHtml( $input ) );
+ // and that htmlDecode and filterHTMLEntities are really the opposite of each other
+// $this->assertEquals( $input, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $input )));
+// $this->assertEquals( $output, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $output )));
+ }
+ }
+
+ }
?>
\ No newline at end of file
More information about the pLog-svn
mailing list