diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php
index a1747296e22..e6c8ea33502 100644
--- a/htdocs/core/class/translate.class.php
+++ b/htdocs/core/class/translate.class.php
@@ -682,7 +682,7 @@ class Translate
}
}
- $str = preg_replace('/([^%])%([^0sd])/', '__percent_parenthesis__', $str);
+ $str = preg_replace('/([^%])%([^%0sdmYIMpHSBb])/', '\1__percent_with_bad_specifier__\2', $str);
if (strpos($key, 'Format') !== 0) {
try {
@@ -693,7 +693,7 @@ class Translate
}
}
- $str = str_replace('__percent_parenthesis__', '%)', $str);
+ $str = str_replace('__percent_with_bad_specifier__', '%', $str);
// We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities because
// we want to keep '"' '' '' '' '' '' '' '
'' '' '' '
' '' '< ' that are reliable HTML tags inside translation strings.
diff --git a/test/phpunit/LangTest.php b/test/phpunit/LangTest.php
index 5b7a22b247e..1cb8c53c532 100644
--- a/test/phpunit/LangTest.php
+++ b/test/phpunit/LangTest.php
@@ -26,7 +26,7 @@
* \remarks To run this script as CLI: phpunit filename.php
*/
-global $conf,$user,$langs,$db;
+global $conf, $user, $langs, $db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
@@ -104,7 +104,7 @@ class LangTest extends CommonClassTest
}
/**
- * testLang
+ * testTransWithHTMLInParam
*
* @return void
*/
@@ -138,6 +138,44 @@ class LangTest extends CommonClassTest
return;
}
+ /**
+ * testTransWithPercent
+ *
+ * @return void
+ */
+ public function testTransWithPercent(): void
+ {
+ global $conf,$user,$langs,$db;
+ $conf = $this->savconf;
+ $user = $this->savuser;
+ $langs = $this->savlangs;
+ $db = $this->savdb;
+
+ include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
+
+ $newlang = new Translate('', $conf);
+ $newlang->setDefaultLang('fr_FR');
+ $newlang->load("main");
+
+ $result = $newlang->trans("DatabaseConnection");
+ print "result=".$result.PHP_EOL;
+ $this->assertEquals('Connexion à la base', $result);
+
+ $result = $newlang->transnoentities("FormatDateHourSecShort");
+ print "result=".$result.PHP_EOL;
+ $this->assertEquals('%d/%m/%Y %H:%M:%S', $result);
+
+ $newlang = new Translate('', $conf);
+ $newlang->setDefaultLang('en_US');
+ $newlang->load("main");
+
+ $result = $newlang->transnoentities("FormatDateHourText");
+ print "result=".$result.PHP_EOL;
+ $this->assertEquals('%B %d, %Y, %I:%M %p', $result);
+
+ return;
+ }
+
/**
* testLang
* @dataProvider langDataProvider