From 57153e4de40cd96576825c2e7856c745119f2060 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 13 Feb 2014 23:40:39 +0100 Subject: [PATCH] Try a cleaner javascript escape function. --- htdocs/core/lib/functions.lib.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 31e2a1344b4..3f5b90df529 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -437,13 +437,18 @@ function dol_string_nospecial($str,$newstr='_',$badchars='') /** * Returns text escaped for inclusion into javascript code * - * @param string $stringtoescape String to escape - * @return string Escaped string + * @param string $stringtoescape String to escape + * @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string" + * @return string Escaped string. Both ' and " are escaped into ' if they are escaped. */ -function dol_escape_js($stringtoescape) +function dol_escape_js($stringtoescape, $mode=0) { // escape quotes and backslashes, newlines, etc. - $substitjs=array("'"=>"\\'",'\\'=>'\\\\',"'"=>"\\'",'"'=>"\\'","\r"=>'\\r',"\n"=>'\\n',''<\/'); + $substitjs=array("'"=>"\\'",'\\'=>'\\\\',"\r"=>'\\r',"\n"=>'\\n'); + //$substitjs['