diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-11-21 00:43:42 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-11-21 00:43:42 +0000 |
commit | 59ceca0caf52002cf44206feec7c7213bc079939 (patch) | |
tree | 795bbe8ed9a00e4d55ce47516d5c6b4aa589c5e0 /includes | |
parent | 34119ba98b9e7b412ed7efdcf7b9e9b704f790c7 (diff) | |
download | brdo-59ceca0caf52002cf44206feec7c7213bc079939.tar.gz brdo-59ceca0caf52002cf44206feec7c7213bc079939.tar.bz2 |
#633156 follow-up by effulgentsia and yched: Clean up AJAX tests, add sister function to drupal_js_encode().
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 16 |
1 files changed, 14 insertions, 2 deletions
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); } /** |