mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'MDL-30741_m22' of git://github.com/jfilip/moodle into MOODLE_22_STABLE
This commit is contained in:
commit
58ca2c4b71
2 changed files with 41 additions and 3 deletions
|
@ -543,9 +543,15 @@ class html2text
|
||||||
*/
|
*/
|
||||||
function _convert_pre(&$text)
|
function _convert_pre(&$text)
|
||||||
{
|
{
|
||||||
while(preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
|
while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
|
||||||
$result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]);
|
// convert the content
|
||||||
$text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1);
|
$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 = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,6 +579,17 @@ class html2text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Strtoupper multibyte wrapper function
|
||||||
*
|
*
|
||||||
|
|
|
@ -139,6 +139,27 @@ class web_test extends UnitTestCase {
|
||||||
$this->assertIdentical('0', 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() {
|
public function test_clean_text() {
|
||||||
$text = "lala <applet>xx</applet>";
|
$text = "lala <applet>xx</applet>";
|
||||||
$this->assertEqual($text, clean_text($text, FORMAT_PLAIN));
|
$this->assertEqual($text, clean_text($text, FORMAT_PLAIN));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue