[pLog-svn] r7240 - in plog/branches/lifetype-1.2/class: data test/tests/data
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Wed Jul 15 06:38:55 EDT 2020
Author: jondaley
Date: 2020-07-15 06:38:55 -0400 (Wed, 15 Jul 2020)
New Revision: 7240
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:
fixed tests for PHP7 (encoding issues) and removed a couple my_preg_replace in favor of the callback version
Modified: plog/branches/lifetype-1.2/class/data/textfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/textfilter.class.php 2020-07-15 09:48:32 UTC (rev 7239)
+++ plog/branches/lifetype-1.2/class/data/textfilter.class.php 2020-07-15 10:38:55 UTC (rev 7240)
@@ -104,9 +104,16 @@
* @param string The string we would like to process
* @return The same string but with the HTML/XML entities encoded to their representation
*/
- function filterHTMLEntities( $string )
+ function filterHTMLEntities( $string, $encoding="" )
{
- return htmlentities( $string );
+ // see PHP documentation for how the default encoding works
+ // for different versions of PHP.
+ // Normally, this will be left blank, but for our unit tests,
+ // we need to pass in a value
+ if($encoding)
+ return htmlentities( $string, ENT_COMPAT | ENT_HTML401, $encoding );
+ else
+ return htmlentities( $string );
}
/**
@@ -224,11 +231,12 @@
function htmlDecode( $htmlString, $quote_style = ENT_QUOTES )
{
// replace numeric entities
- // TODO: check these
- $htmlString = my_preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $htmlString);
- $htmlString = my_preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $htmlString);
+ $htmlString = preg_replace_callback('~&#x([0-9a-f]+);~i',
+ function($m){ return chr(hexdec($m[1])); }, $htmlString);
+ $htmlString = preg_replace_callback('~&#([0-9]+);~',
+ function($m){ return chr($m[1]); }, $htmlString);
// get the entity translation table from PHP (current encoding is ISO-8859-1)
- $trans_table = get_html_translation_table( HTML_ENTITIES, $quote_style );
+ $trans_table = get_html_translation_table( HTML_ENTITIES, $quote_style, "ISO-8859-1" );
// when we want to decode the input string to normalized string, there are two factors
// we need to take into consideration:
// - Input string encoding
@@ -252,7 +260,8 @@
// Keep original ISO-8859-1 translation table, just flip it
$new_trans_table = array_flip($trans_table);
}
- return strtr( $htmlString, $new_trans_table );
+ $htmlString = strtr( $htmlString, $new_trans_table );
+ return $htmlString;
}
/**
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 2020-07-15 09:48:32 UTC (rev 7239)
+++ plog/branches/lifetype-1.2/class/test/tests/data/textfilter_test.class.php 2020-07-15 10:38:55 UTC (rev 7240)
@@ -111,7 +111,8 @@
"&" => "&",
"test" => "test",
"áé" => "áé",
- "äÜ" => "äÜ"
+ "äÜ" => "äÜ",
+ "&" => "&",
);
foreach( $tests as $input => $output ) {
@@ -118,8 +119,8 @@
// check that the input is equal to the output after processing it with TextFilter::htmlDecode
$this->assertEquals( $output, TextFilter::htmlDecode( $input ), "Error htmlDecode()-ing string: $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 )));
+ $this->assertEquals( $input, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $input, "ISO-8859-1" )));
+ $this->assertEquals( $output, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $output, "ISO-8859-1" )));
}
}
@@ -160,4 +161,4 @@
}
}
-?>
\ No newline at end of file
+?>
More information about the pLog-svn
mailing list