[squeak-dev] WebUtils class jsonNumberFrom: broken

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Sep 10 22:01:13 UTC 2019


Hi,
there are a number of mistakes in this method, see by yourself:

{
WebUtils jsonNumberFrom:  '1.e-1' readStream.
WebUtils jsonNumberFrom:  '1.e+1' readStream.
WebUtils jsonNumberFrom:  '1e1,1e2' readStream.
WebUtils jsonNumberFrom:  '1e+,1e2' readStream.
WebUtils jsonNumberFrom:  '1e-,1e2' readStream.
WebUtils jsonNumberFrom:  '1.1e30' readStream.
}

First one because we compare ascii value (an Integer) to $- (the
Character)...
2nd one same for +
Third one because we decide to do nothing when exponent = 1
4th and 5th are variations of 1st and 2nd

Moreover, the conversions are subject to double rounding problem (it main
chain up to 3 inexact operations), it will thus fail to answer the nearest
Float to some json string. This is bad, ECMA script does not make such
mistake.

self assert: ( WebUtils jsonNumberFrom:  '1.1e30' ) = 1.1e30

There is no use to get a false result fast IMO...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190911/2abaa85f/attachment.html>


More information about the Squeak-dev mailing list