From 7f3ed109225b01ee9b40a02417d2137dbbd539dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2024 04:08:54 +0200 Subject: [PATCH] Add phpunit case --- htdocs/core/lib/functions.lib.php | 2 ++ test/phpunit/SecurityTest.php | 37 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a318fe2f04a..26030e25e38 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8118,6 +8118,8 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' // like '

Foo

bar

' that wrongly ends up, without the trick, with '

Foo

bar

' // like 'abc' that wrongly ends up, without the trick, with '

abc

' + // TODO Must accept emoji with MAIN_RESTRICTHTML_ONLY_VALID_HTML... + if (dol_textishtml($out)) { $out = '
'.$out.'
'; } else { diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 564307bd202..928faf56d03 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -1110,6 +1110,43 @@ class SecurityTest extends CommonClassTest $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.