This project is archived and is in readonly mode.

#781 ✓invalid
Chris Buckley

JSON.encode for arguments object

Reported by Chris Buckley | November 11th, 2009 @ 01:10 PM | in 2.0 (closed)

JSON.encode does not encode an arguments object, where it could treat it as an array. Suggest adding the following case which passes on to the array case:

switch ($type(obj)){
    case 'string':
        return '"' + obj.replace(/[\x00-\x1f\\"]/g, JSON.$replaceChars) + '"';
    case 'arguments':
        for (var i = 0, tmp = []; i < obj.length; i++) tmp.push(obj[i]);
        obj = tmp;
    case 'array':
        return '[' + String( + ']';
    case 'object': case 'hash':
        var string = [];
        Hash.each(obj, function(value, key){
            var json = JSON.encode(value);
            if (json) string.push(JSON.encode(key) + ':' + json);
        return '{' + string + '}';
    case 'number': case 'boolean': return String(obj);
    case false: return 'null';

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket