From 59ceca0caf52002cf44206feec7c7213bc079939 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 21 Nov 2009 00:43:42 +0000 Subject: #633156 follow-up by effulgentsia and yched: Clean up AJAX tests, add sister function to drupal_js_encode(). --- includes/common.inc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index be8f2a974..22d58488d 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4342,10 +4342,22 @@ function drupal_clear_js_cache() { * Converts a PHP variable into its Javascript equivalent. * * We use HTML-safe strings, i.e. with <, > and & escaped. + * + * @see drupal_json_decode() */ function drupal_json_encode($var) { - // json_encode() does not escape <, > and &, so we do it with str_replace() - return str_replace(array("<", ">", "&"), array('\x3c', '\x3e', '\x26'), json_encode($var)); + // json_encode() does not escape <, > and &, so we do it with str_replace(). + return str_replace(array('<', '>', '&'), array('\x3c', '\x3e', '\x26'), json_encode($var)); +} + +/** + * Converts an HTML-safe JSON string into its PHP equivalent. + * + * @see drupal_json_encode() + */ +function drupal_json_decode($var) { + // json_decode() does not unescape <, > and &, so we do it with str_replace(). + return json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array('<', '>', '&'), $var), TRUE); } /** -- cgit v1.2.3