onrails.org home

To Infinity and... no beyond - An ActionScript bug...I mean, feature.

So yesterday I was asked about a bug in a legacy Rails and Flex application. There was one company name that wasn’t displayed correctly on the front-end. “Infinity Corp Name” was just displayed as “Infinity”, so nothing beyond infinity. First I thought it was a joke, but not, a real bug that could cause issues.

So I looked at the code and the service call was a plain HttpService call with the resultFormat set to object. The server returns XML but the Flash Player converts the XML to a tree of objects. This is where it get’s funny. In fact when the player converts your hash to Objects it checks if a value is a number or a string…Hey guess what “Infinity followed by something” is a number.

Here are some conversion examples:

String Is Number Converted Number
“123” true 123
“123 Abc” false NaN
“Infinity” true Infinity
“Infinity Abc” true Infinity

It’s the last conversion which is the root of the problem as “Infinity Abc” is a number that when casted translates to Infinity!

So we found the problem but the solution is really don’t use the Flash Player to do the conversion for you using the return type “object”. Use “e4x” which would turn your object in XML or use JSON and do the conversion yourself.

To Infinity… and beyond!

Daniel

Fork me on GitHub