diff --git a/lib/simpletest/testweblib.php b/lib/simpletest/testweblib.php index 27359ce88a5..35caacab4cd 100644 --- a/lib/simpletest/testweblib.php +++ b/lib/simpletest/testweblib.php @@ -23,6 +23,8 @@ class web_test extends UnitTestCase { } function test_format_string() { + global $CFG; + // Ampersands $this->assertEqual(format_string("& &&&&& &&"), "& &&&&& &&"); $this->assertEqual(format_string("ANother & &&&&& Category"), "ANother & &&&&& Category"); @@ -37,6 +39,21 @@ class web_test extends UnitTestCase { // Unicode entities $this->assertEqual(format_string("ᅻ"), "ᅻ"); + + // < and > signs + $originalformatstringstriptags = $CFG->formatstringstriptags; + + $CFG->formatstringstriptags = false; + $this->assertEqual(format_string('x < 1'), 'x < 1'); + $this->assertEqual(format_string('x > 1'), 'x > 1'); + $this->assertEqual(format_string('x < 1 and x > 0'), 'x < 1 and x > 0'); + + $CFG->formatstringstriptags = true; + $this->assertEqual(format_string('x < 1'), 'x < 1'); + $this->assertEqual(format_string('x > 1'), 'x > 1'); + $this->assertEqual(format_string('x < 1 and x > 0'), 'x < 1 and x > 0'); + + $CFG->formatstringstriptags = $originalformatstringstriptags; } function test_s() { diff --git a/lib/weblib.php b/lib/weblib.php index eadfe5d8cf3..89bdce5d639 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1179,11 +1179,9 @@ function reset_text_filters_cache() { * need filter processing e.g. activity titles, post subjects, * glossary concepts. * - * @global object - * @global object - * @global object * @staticvar bool $strcache - * @param string $string The string to be filtered. + * @param string $string The string to be filtered. Should be plain text, expect + * possibly for multilang tags. * @param boolean $striplinks To strip any link in the result text. Moodle 1.8 default changed from false to true! MDL-8713 * @param array $options options array/object or courseid @@ -1241,7 +1239,7 @@ function format_string($string, $striplinks = true, $options = NULL) { // If the site requires it, strip ALL tags from this string if (!empty($CFG->formatstringstriptags)) { - $string = strip_tags($string); + $string = str_replace(array('<', '>'), array('<', '>'), strip_tags($string)); } else { // Otherwise strip just links if that is required (default)