diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-03-08 19:33:55 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-03-08 19:33:55 +0000 |
commit | d9ece0d575151e0ef2b8994a19f672f9104afc3a (patch) | |
tree | 23484c2e7c36c5b91c8a5ae1cac00f62de391154 /includes | |
parent | 0cb5532a23725e597ea3526dfa99ff5c27b0bd63 (diff) | |
download | brdo-d9ece0d575151e0ef2b8994a19f672f9104afc3a.tar.gz brdo-d9ece0d575151e0ef2b8994a19f672f9104afc3a.tar.bz2 |
- Patch #121876 by Darren, Nedjo et al: drupal_to_js converts empty arrays to objects.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc index 6c442e5b3..63973c499 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1762,14 +1762,17 @@ function drupal_to_js($var) { array('\r', '\n', '\x3c', '\x3e', '\x26'), addslashes($var)) .'"'; case 'array': - if (array_keys($var) === range(0, sizeof($var) - 1)) { + // Arrays in JSON can't be associative. If the array is empty or if it + // has sequential whole number keys starting with 0, it's not associative + // so we can go ahead and convert it as an array. + if (empty ($var) || array_keys($var) === range(0, sizeof($var) - 1)) { $output = array(); foreach ($var as $v) { $output[] = drupal_to_js($v); } return '[ '. implode(', ', $output) .' ]'; } - // Fall through + // Otherwise, fall through to convert the array as an object. case 'object': $output = array(); foreach ($var as $k => $v) { |