ejayimperial / google-caja

Automatically exported from code.google.com/p/google-caja
0 stars 0 forks source link

doesn't handle null value in the defaultFilter #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. calling the serialize on an object with a null property

What is the expected output? What do you see instead?
one error in firebug

please find below a fix for the defaultFilter.

/* default filter */
    function defaultFilter(baseObj, key) {
        var result;

        if (typeof key === 'string') {
            if (!Object.prototype.hasOwnProperty.call(baseObj, key)) {
                return undefined;
            }
        } else if (typeof key === 'number') {
            if (!(baseObj instanceof Array)) {
                return undefined;
            }
        } else {
            return undefined;
        }
        result = baseObj[key];

        if(!result) { return undefined; }        

        if (typeof result.toJSON === 'function') {
            return result.toJSON();
        } else {
            return result;
        }
    }

Original issue reported on code.google.com by sylvain....@gmail.com on 19 Oct 2007 at 1:41

GoogleCodeExporter commented 9 years ago
Fixed, but differently than you suggested. Rather than adding a

  if(!result) { return undefined; } 

I instead changed the following line to

  if (result && typeof result.toJSON === 'function') {

Original comment by erights on 21 Oct 2007 at 1:35