Permalink
Browse files

Merge branch 'MDL-31101_22' of git://github.com/timhunt/moodle into M…

…OODLE_22_STABLE
  • Loading branch information...
2 parents 4cb258f + 8261570 commit e516577ec7b90457fa5224baa82566f42c30f6e9 @stronk7 stronk7 committed Jan 10, 2012
Showing with 20 additions and 5 deletions.
  1. +17 −0 lib/simpletest/testweblib.php
  2. +3 −5 lib/weblib.php
View
17 lib/simpletest/testweblib.php
@@ -23,6 +23,8 @@ function tearDown() {
}
function test_format_string() {
+ global $CFG;
+
// Ampersands
$this->assertEqual(format_string("& &&&&& &&"), "& &&&&& &&");
$this->assertEqual(format_string("ANother & &&&&& Category"), "ANother & &&&&& Category");
@@ -37,6 +39,21 @@ function test_format_string() {
// Unicode entities
$this->assertEqual(format_string("ᅻ"), "ᅻ");
+
+ // < and > signs
+ $originalformatstringstriptags = $CFG->formatstringstriptags;
+
+ $CFG->formatstringstriptags = false;
+ $this->assertEqual(format_string('x < 1'), 'x &lt; 1');
+ $this->assertEqual(format_string('x > 1'), 'x &gt; 1');
+ $this->assertEqual(format_string('x < 1 and x > 0'), 'x &lt; 1 and x &gt; 0');
+
+ $CFG->formatstringstriptags = true;
+ $this->assertEqual(format_string('x < 1'), 'x &lt; 1');
+ $this->assertEqual(format_string('x > 1'), 'x &gt; 1');
+ $this->assertEqual(format_string('x < 1 and x > 0'), 'x &lt; 1 and x &gt; 0');
+
+ $CFG->formatstringstriptags = $originalformatstringstriptags;
}
function test_s() {
View
8 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('&lt;', '&gt;'), strip_tags($string));
} else {
// Otherwise strip just links if that is required (default)

0 comments on commit e516577

Please sign in to comment.