diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e436c45cfb5..868815a49b8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2015,12 +2015,13 @@ function dol_escape_xml($stringtoescape) * Return a string label (so on 1 line only and that should not contains any HTML) ready to be output on HTML page. * To use text that is not HTML content inside an attribute, you can simply use only dol_escape_htmltag(). In doubt, use dolPrintHTMLForAttribute(). * - * @param string $s String to print - * @return string String ready for HTML output + * @param string $s String to print + * @param int $escapeonlyhtmltags 1=Escape only html tags, not the special chars like accents. + * @return string String ready for HTML output */ -function dolPrintLabel($s) +function dolPrintLabel($s, $escapeonlyhtmltags = 0) { - return dol_escape_htmltag(dol_string_nohtmltag($s, 1, 'UTF-8', 0, 0), 0, 0, '', 0, 1); + return dol_escape_htmltag(dol_string_nohtmltag($s, 1, 'UTF-8', 0, 0), 0, 0, '', $escapeonlyhtmltags, 1); } /** @@ -2051,18 +2052,23 @@ function dolPrintHTML($s, $allowiframe = 0) } /** - * Return a string ready to be output on an HTML attribute (alt, title, data-html, ...) + * Return a string ready to be output into an HTML attribute (alt, title, data-html, ...) * With dolPrintHTMLForAttribute(), the content is HTML encode, even if it is already HTML content. * - * @param string $s String to print - * @return string String ready for HTML output + * @param string $s String to print + * @param int $escapeonlyhtmltags 1=Escape only html tags, not the special chars like accents. + * @return string String ready for HTML output * @see dolPrintHTML(), dolPrintHTMLFortextArea() */ -function dolPrintHTMLForAttribute($s) +function dolPrintHTMLForAttribute($s, $escapeonlyhtmltags = 0) { - // The dol_htmlentitiesbr will convert simple text into html - // The dol_escape_htmltag will escape html chars. - return dol_escape_htmltag(dol_string_onlythesehtmltags(dol_htmlentitiesbr($s), 1, 0, 0, 0, array('br', 'b', 'font', 'hr', 'span')), 1, -1, '', 0, 1); + // The dol_htmlentitiesbr will convert simple text into html, including switching accent into HTML entities + // The dol_escape_htmltag will escape html tags. + if ($escapeonlyhtmltags) { + return dol_escape_htmltag(dol_string_onlythesehtmltags($s, 1, 0, 0, 0, array('br', 'b', 'font', 'hr', 'span')), 1, -1, '', 1, 1); + } else { + return dol_escape_htmltag(dol_string_onlythesehtmltags(dol_htmlentitiesbr($s), 1, 0, 0, 0, array('br', 'b', 'font', 'hr', 'span')), 1, -1, '', 0, 1); + } } /**