diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 32bf09fddc5..b55214b6bb6 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -9550,8 +9550,18 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = '
$matches = array();
if (preg_match_all($pattern, $out, $matches)) {
- // URLs are into $matches[1]
- $urls = $matches[1];
+ // URLs are into $matches[1] or $matches[2]
+ $urls = array();
+ foreach ($matches[1] as $tmpval) {
+ if (!empty($tmpval)) {
+ $urls[] = $tmpval;
+ }
+ }
+ foreach ($matches[2] as $tmpval) {
+ if (!empty($tmpval)) {
+ $urls[] = $tmpval;
+ }
+ }
// Show URLs
$firstexturl = '';
diff --git a/test/phpunit/SecurityGETPOSTTest.php b/test/phpunit/SecurityGETPOSTTest.php
index 349522241be..ed423c6cdea 100644
--- a/test/phpunit/SecurityGETPOSTTest.php
+++ b/test/phpunit/SecurityGETPOSTTest.php
@@ -490,13 +490,13 @@ class SecurityGETPOSTTest extends CommonClassTest
$_POST["pagecontentwithnowrapperlinks"] = '
';
$result = GETPOST("pagecontentwithnowrapperlinks", 'restricthtml');
print __METHOD__." result=".$result."\n";
- $this->assertEquals('ErrorHTMLExternalLinksNotAllowed', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)');
+ $this->assertEquals('ErrorHTMLExternalLinksNotAllowed (Example: https://aaa)', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)');
// Test that links not on wrapper and not data are disallowed
$_POST["pagecontentwithnowrapperlinks"] = '';
$result = GETPOST("pagecontentwithnowrapperlinks", 'restricthtml');
print __METHOD__." result=".$result."\n";
- $this->assertEquals('ErrorHTMLExternalLinksNotAllowed', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)');
+ $this->assertEquals('ErrorHTMLExternalLinksNotAllowed (Example: http://ddd)', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)');
// Test substitution in GET url