nmosafi/aspComet — Issue #16: MessageConverter.ToJson Error  [{,
Author: bloublou
Created: 2011-12-29 16:33:06+00:00
State: open

Hello, thanks for your project.

Env: VS2010, .net4
Browser: FF9.0.1, IE9
Sys: Sys7 x64
Program : Chat-vs2010
Version : downloaded 23/12/2011 23h33

Bug :
Sometimes MessageConverter.ToJson send back a "bad" string with error on format.
Example :

case 1 : FF9.0.1, when click on handshake from cometdTerminal.html
Post on comet.axd/handshake
[{"ext":{"authentication":{"user":"User","credentials":"password"}},"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling"],"id":6}]

Returns :
[{,"version":"1.0","channel":"/meta/handshake","supportedConnectionTypes":["long-polling"],"id":"1","clientId":"Ngv9SfTkgSKQeEaElqZ","advice":{"reconnect":"retry"},"successful":true}]

FF made an error : JSON.parse: expected property name or '}'
return JSON.parse(src); on function $.secureEvalJSON = function(src)
Supposed error : [{, coma should not be there

Under IE : it seems IE does not care but no event is took into consideration.

Possible origin :

MessageConverter.CreateNullRegexString()
You create a long Regex with a lot of possibilities :

("channel":null,)|(,"channel":null)|("clientId":null,)|(,"clientId":null)|("data":null,)|(,"data":null)|("version":null,)|(,"version":null)|("minimumVersion":null,)|(,"minimumVersion":null)|("supportedConnectionTypes":null,)|(,"supportedConnectionTypes":null)|("advice":null,)|(,"advice":null)|("connectionType":null,)|(,"connectionType":null)|("id":null,)|(,"id":null)|("timestamp":null,)|(,"timestamp":null)|("successful":null,)|(,"successful":null)|("subscription":null,)|(,"subscription":null)|("error":null,)|(,"error":null)|("ext":null)|(,"ext":null)

with case 1 message is :
[{"ext":null,"version":"1.0","minimumVersion":null,"channel":"/meta/handshake","supportedConnectionTypes":["long-polling"],"id":"2","clientId":"Xg6gcCTsc7Tgofof60p","data":null,"advice":{"reconnect":"retry"},"connectionType":null,"timestamp":null,"successful":true,"subscription":null,"error":null}]

Converted message :
[{,"version":"1.0","channel":".....

NullRegexString could be
{"[^"\*]+":null[,}]?|,"[^"\*]+":null
considering : {"blabla":null, {"blabla":null} ,"blabla":null
and message will be fine.