From 93a0962864859703dca5d6603f6bfd06c029974f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 3 May 2010 15:18:39 +0200 Subject: [PATCH 1/2] Move function to js escaping library. --- js/messages.php | 13 ------------- libraries/js_escape.lib.php | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/js/messages.php b/js/messages.php index 31cecf126..3d10d496a 100644 --- a/js/messages.php +++ b/js/messages.php @@ -22,19 +22,6 @@ require_once './libraries/common.inc.php'; // But this one is needed for PMA_escapeJsString() require_once './libraries/js_escape.lib.php'; -function PMA_printJsValue($key, $value) { - echo $key . ' = '; - if (is_array($value)) { - echo '['; - foreach ($value as $id => $val) { - echo "'" . PMA_escapeJsString($val) . "',\n"; - } - echo "];\n"; - } else { - echo "'" . PMA_escapeJsString($value) . "';\n"; - } -} - $js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty']; $js_messages['strNotNumber'] = $GLOBALS['strNotNumber']; $js_messages['strClickToSelect'] = $GLOBALS['strClickToSelect']; diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 51673464a..cb1a21a0c 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -64,4 +64,24 @@ function PMA_escapeJsString($string) "\r" => '\r'))); } +/** + * Prints an javascript assignment with proper escaping of a value + * and support for assigning array of strings. + * + * @param string $key Name of value to set + * @param mixed $value Value to set, can be either string or array of strings + */ +function PMA_printJsValue($key, $value) { + echo $key . ' = '; + if (is_array($value)) { + echo '['; + foreach ($value as $id => $val) { + echo "'" . PMA_escapeJsString($val) . "',\n"; + } + echo "];\n"; + } else { + echo "'" . PMA_escapeJsString($value) . "';\n"; + } +} + ?> From c2260ccb41081b72d14958dff4acacf1ca941ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 4 May 2010 09:07:55 +0200 Subject: [PATCH 2/2] Generate more compact output. --- libraries/js_escape.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index cb1a21a0c..8bec9c0ef 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -76,7 +76,7 @@ function PMA_printJsValue($key, $value) { if (is_array($value)) { echo '['; foreach ($value as $id => $val) { - echo "'" . PMA_escapeJsString($val) . "',\n"; + echo "'" . PMA_escapeJsString($val) . "',"; } echo "];\n"; } else {