Skip to content

Commit

Permalink
Merge branch 'MDL-30741_m22' of git://github.com/jfilip/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_22_STABLE
  • Loading branch information
stronk7 committed Dec 19, 2011
2 parents 4e77491 + e0b587b commit 58ca2c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/html2text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
}

Expand Down Expand Up @@ -573,6 +579,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
*
Expand Down
21 changes: 21 additions & 0 deletions lib/simpletest/testweblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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));
Expand Down

0 comments on commit 58ca2c4

Please sign in to comment.