Ichoran / kse

The Kerr Scala Extensions contain core functionality missing from the Scala standard library.
Other
28 stars 4 forks source link

Jsonal does not take into account 'E' #1

Closed mdedetrich closed 8 years ago

mdedetrich commented 8 years ago

It appears that some of the code in jsonal doesn't take into account the character 'E', which according to the JSON spec, is an alias for 'e' (i.e. the exponent).

You can see https://tools.ietf.org/html/rfc4627 for more info, specifically

         number = [ minus ] int [ frac ] [ exp ]

         decimal-point = %x2E       ; .

         digit1-9 = %x31-39         ; 1-9

         e = %x65 / %x45            ; e E

         exp = e [ minus / plus ] 1*DIGIT

         frac = decimal-point 1*DIGIT

         int = zero / ( digit1-9 *DIGIT )

         minus = %x2D               ; -

         plus = %x2B                ; +

         zero = %x30                ; 0
Ichoran commented 8 years ago

@mdedetrich - Can you write some code that actually demonstrates this bug? Note that (c | 0x20) converts to lower-case, so (c | 0x20) == 'e' is a slightly faster way to write (c == 'e' || c == 'E'). (At least in my microbenchmarks.)

Ichoran commented 8 years ago

Here are cases where it works, which I think is an exhaustive list:

Jast parse "[1e2, 1E2, 1.1e2, 1.1E2]"
Jast parse java.nio.ByteBuffer.wrap("[1e2, 1E2, 1.1e2, 1.1E2]".getBytes)
Jast parse java.nio.CharBuffer.wrap("[1e2, 1E2, 1.1e2, 1.1E2]".toCharArray)
Jast parse (new java.io.ByteArrayInputStream("[1e2, 1E2,  1.1e2, 1.1E2]".getBytes))
mdedetrich commented 8 years ago

Actually nvm then, didn't realise that (c | 0x20) was a shortcut method for converting to lowercase, closing the issue