PDA

View Full Version : [FIXED]Ext.JSON encode bug?



gevik
17 Feb 2011, 1:20 PM
Hi,

The Ext.JSON.encode method in Ext4 is unable to handle object types that it does not recognize.

If you check the doEncode method in extras.js:28-45, the "if condition" does not default to a value (preferably null), when none of the checks before qualify. The doEncode method in 3.3.1 did this.

This is pretty serious since in different browser environments you have different (inconsistent) object types.

So what is an encoded JSON look like when it happens:
{"BrowserEvent":,"Number":1,"String",:"Foo"}

So where will this bite us?
For starters: Ext.Direct will most certainly break if you pass event objects (MouseEvent for example) as a direct method argument.

Possible solution:
Either enhance the doEncode method to default unrecognized object types to null, like it was in 3.2.1

Or make Ext.isObject beter. (easier said than done, I know....)

Little test code:


Ext.widget('button',{
text:'Click Me',
renderTo:Ext.getBody(),
listeners:{
click:function(sender,e)
{
var json = Ext.JSON.encode(e);
console.info(json);
}
}
});


Result:

{"browserEvent":,"type":"click","button":0,"shiftKey":false,"ctrlKey":false,"altKey":false,"keyCode":null,"charCode":null,"target":,"relatedTarget":null,"currentTarget":,"xy":[165,13]}

evant
19 Feb 2011, 3:46 AM
I'm not really sure what you're getting at here.

If I run the equivalent code in 3.3.1 I get a stack overflow exception.



Ext.onReady(function(){
new Ext.Button({
text: 'Click Me',
renderTo: Ext.getBody(),
listeners: {
click: function(sender, e){
try {
var json = Ext.util.JSON.encode(e);
console.info(json);
}catch(ex) {
console.log(ex.message);
}
}
}
});

});

gevik
19 Feb 2011, 4:19 AM
Humm.. I ran the code also on 3.3.1 and don't get any errors.
What I'm trying to say here is that the JSON encoder in Ext4 is not able to encode all object types.

In Ext3 I get:
{"browserEvent":{},"button": .......... }

In Ext4 I get:
{"browserEvent":,"button":................}

There is no value for browserEvent?

evant
20 Feb 2011, 6:49 PM
Ok I'm with you. I've added a fix to ensure that it includes a value.

gevik
21 Feb 2011, 3:34 AM
What would be that value? null? or and empty object {}