Skip to content
This repository

(2.6 and 3.0) fix json parser e+ bug #1492

Closed
wants to merge 1 commit into from

5 participants

Mikhail Strebkov Antonio Salazar Cardozo David Pollak Joni Freeman Diego Medina
Mikhail Strebkov

According to http://www.json.org/ the double in JSON can be represented in scientific notation, and e symbol can be one of the following:
e
e+
e-
E
E+
E-
net.liftweb.json.parse was working ok with e, e-, E, E- but was throwing exception "can't parse" for e+ and E+.
Added unit test (was failing). Added c == '+' analogous to c == '-' to JsonParser.scala. This fixed unit test.
P.S. The same issue exists in master, but we use 2.4 so I fixed it in 2.4 branch. The change is atomic and can be merged to any lift version, including master.

Antonio Salazar Cardozo
Collaborator

Given that this isn't a mission-critical bug, I don't know that it merits a special release of 2.4.

:+1: for the fix to land in 2.6 and 3.0, however.

Antonio Salazar Cardozo
Collaborator

Er… Actually… Before I forget… Did you discuss this on the mailing list before issuing the PR? It doesn't look like it. Please read the contribution guidelines, which are listed whenever you open an issue or pull request.

Mikhail Strebkov

@Shadowfiend Ups, sorry about that. It's my very first pull-request. Just wrote to the mailing list: https://groups.google.com/forum/#!topic/liftweb/dvlgelrPfFg
contributors.md doesn't exist in 2.4 branch.
Should I remove this pull-request and prepare another one for "master" branch after discussion in mailing list and with contributors.md changes?

The change is pretty small, but the issue is critical to me - I use lift-json to parse json from third-party services and one of them returns numbers in this format, which is valid json, but can't be parsed by lift-json.

By submitting this pull request which includes my name and email address
(the email address may be in a non-robot readable format), I agree that the
entirety of the contribution is my own original work, that there are no prior
claims on this work including, but not limited to, any agreements I may have with
my employer or other contracts, and that I license this work under
an Apache 2.0 license.

Name:

Mikhail Strebkov

Email:

strebkov @@ gmail .. com

David Pollak
Owner
Mikhail Strebkov

Prior to the 2.5 release, we only accepted contributions from committers.
We relaxed that with the 2.5 release.

I see. Great that this was relaxed.

We will only roll this into Master and lift_30. We will not backport it
(unless you are willing to pay for the time it takes to roll new versions
of prior releases of Lift.) The only thing we backport is critical security
fixes for which there are no reasonable work-arounds.

I see. I can live with my own jar's until lift_30.

So should I remove pull-request and prepare another one for master? Or remove and wait for Joni Freeman?

Joni Freeman

Looks good to me. Double checked the spec too and [num] e+ [exp] is a valid representation for a decimal number.

David Pollak
Owner
Diego Medina
Owner

rebased to master, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 10, 2013
Mikhail Strebkov Fixed parsing json double values in scientific notation with e+ a37cb9c
This page is out of date. Refresh to see the latest.
2  core/json/src/main/scala/net/liftweb/json/JsonParser.scala
@@ -250,7 +250,7 @@ object JsonParser {
250 250 if (c == '.' || c == 'e' || c == 'E') {
251 251 doubleVal = true
252 252 s.append(c)
253   - } else if (!(Character.isDigit(c) || c == '.' || c == 'e' || c == 'E' || c == '-')) {
  253 + } else if (!(Character.isDigit(c) || c == '.' || c == 'e' || c == 'E' || c == '-' || c == '+')) {
254 254 wasInt = false
255 255 buf.back
256 256 } else s.append(c)
6 core/json/src/test/scala/net/liftweb/json/ParserBugs.scala
@@ -52,6 +52,12 @@ object ParserBugs extends Specification {
52 52 parse(s) mustEqual json
53 53 }
54 54
  55 + "Double in scientific notation with + can be parsed" in {
  56 + val json = JObject(List(JField("t", JDouble(12.3))))
  57 + val s = """{"t" : 1.23e+1}"""
  58 + parse(s) mustEqual json
  59 + }
  60 +
55 61 private val discardParser = (p : JsonParser.Parser) => {
56 62 var token: JsonParser.Token = null
57 63 do {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.