Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-30741_m21' of git://github.com/jfilip/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
commit 6e1f50f2c84db94a6e63d4807ea9ef3fefa2f665 2 parents 490f178 + 54e44c1
Eloy Lafuente (stronk7) stronk7 authored
Showing with 41 additions and 3 deletions.
  1. +20 −3 lib/html2text.php
  2. +21 −0 lib/simpletest/testweblib.php
23 lib/html2text.php
View
@@ -543,9 +543,15 @@ function _build_link_list( $link, $display )
*/
function _convert_pre(&$text)
{
- while(preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
- $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]);
- $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1);
+ while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
+ // convert the content
+ $this->pre_content = sprintf('<div><br>%s<br></div>',
+ preg_replace($this->pre_search, $this->pre_replace, $matches[1]));
+ // replace the content (use callback because content can contain $0 variable)
+ $text = preg_replace_callback('/<pre[^>]*>.*<\/pre>/ismU',
+ array('html2text', '_preg_pre_callback'), $text, 1);
+ // free memory
+ $this->pre_content = '';
}
}
@@ -574,6 +580,17 @@ function _preg_callback($matches)
}
/**
+ * Callback function for preg_replace_callback use in PRE content handler.
+ *
+ * @param array PREG matches
+ * @return string
+ */
+ private function _preg_pre_callback($matches)
+ {
+ return $this->pre_content;
+ }
+
+ /**
* Strtoupper multibyte wrapper function
*
* @param string $str
21 lib/simpletest/testweblib.php
View
@@ -144,6 +144,27 @@ public function test_html_to_text_0() {
$this->assertIdentical('0', html_to_text('0'));
}
+ public function test_html_to_text_pre_parsing_problem() {
+ $strorig = 'Consider the following function:<br /><pre><span style="color: rgb(153, 51, 102);">void FillMeUp(char* in_string) {'.
+ '<br /> int i = 0;<br /> while (in_string[i] != \'\0\') {<br /> in_string[i] = \'X\';<br /> i++;<br /> }<br />'.
+ '}</span></pre>What would happen if a non-terminated string were input to this function?<br /><br />';
+
+ $strconv = 'Consider the following function:
+
+void FillMeUp(char* in_string) {
+ int i = 0;
+ while (in_string[i] != \'\0\') {
+ in_string[i] = \'X\';
+ i++;
+ }
+}
+What would happen if a non-terminated string were input to this function?
+
+';
+
+ $this->assertIdentical($strconv, html_to_text($strorig));
+ }
+
public function test_clean_text() {
$text = "lala <applet>xx</applet>";
$this->assertEqual($text, clean_text($text, FORMAT_PLAIN));
Please sign in to comment.
Something went wrong with that request. Please try again.