Add option to escape() to keep user lang codes intact #1976

This commit is contained in:
Kijin Sung 2022-08-15 18:06:23 +09:00
parent 170f7f95b9
commit 8abe1b1d7d
2 changed files with 14 additions and 3 deletions

View file

@ -180,12 +180,20 @@ function clean_path($path)
*
* @param string $str The string to escape
* @param bool $double_escape Set this to false to skip symbols that are already escaped (default: true)
* @param bool $except_lang_code Set this to true to skip user lang codes (default: false)
* @return string
*/
function escape($str, $double_escape = true)
function escape($str, $double_escape = true, $except_lang_code = false)
{
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
return htmlspecialchars($str, $flags, 'UTF-8', $double_escape);
if ($except_lang_code && preg_match('/^\$user_lang->userLang[0-9]+$/', $str))
{
return $str;
}
else
{
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
return htmlspecialchars($str, $flags, 'UTF-8', $double_escape);
}
}
/**