2
0
forked from Wavyzz/dolibarr

Add phpunit case

This commit is contained in:
Laurent Destailleur
2024-05-14 04:08:54 +02:00
parent 3c4a2f6243
commit 7f3ed10922
2 changed files with 39 additions and 0 deletions

View File

@@ -8118,6 +8118,8 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = '
// like '<h1>Foo</h1><p>bar</p>' that wrongly ends up, without the trick, with '<h1>Foo<p>bar</p></h1>' // like '<h1>Foo</h1><p>bar</p>' that wrongly ends up, without the trick, with '<h1>Foo<p>bar</p></h1>'
// like 'abc' that wrongly ends up, without the trick, with '<p>abc</p>' // like 'abc' that wrongly ends up, without the trick, with '<p>abc</p>'
// TODO Must accept emoji with MAIN_RESTRICTHTML_ONLY_VALID_HTML...
if (dol_textishtml($out)) { if (dol_textishtml($out)) {
$out = '<?xml encoding="UTF-8"><div class="tricktoremove">'.$out.'</div>'; $out = '<?xml encoding="UTF-8"><div class="tricktoremove">'.$out.'</div>';
} else { } else {

View File

@@ -1110,6 +1110,43 @@ class SecurityTest extends CommonClassTest
$this->assertStringContainsString('Bad string syntax to evaluate', $result); $this->assertStringContainsString('Bad string syntax to evaluate', $result);
} }
/**
* testDolHtmlWithNoJs()
*
* @return int
*/
public function testDolHtmlWithNoJs()
{
global $conf;
$sav1 = $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML;
$sav2 = $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY;
// Test with an emoji
$test = 'abc ✅ def';
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0;
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1;
$result = dol_htmlwithnojs($test);
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = $sav1;
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = $sav2;
print __METHOD__." result for dol_htmlwithnojs and MAIN_RESTRICTHTML_ONLY_VALID_HTML=0 with emoji = ".$result."\n";
$this->assertEquals($test, $result, 'dol_htmlwithnojs failed with an emoji when MAIN_RESTRICTHTML_ONLY_VALID_HTML=0');
/*
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 1;
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1;
$result = dol_htmlwithnojs($test);
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = $sav1;
$conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = $sav2;
print __METHOD__." result for dol_htmlwithnojs and MAIN_RESTRICTHTML_ONLY_VALID_HTML=1 with emoji = ".$result."\n";
$this->assertEquals($test, $result, 'dol_htmlwithnojs failed with an emoji when MAIN_RESTRICTHTML_ONLY_VALID_HTML=1');
*/
return 0;
}
/** /**
* testDolPrintHTML. * testDolPrintHTML.