You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/05/27 21:28:34 UTC

[3/4] groovy git commit: GROOVY-7979: Check for single minus in NumberValue

GROOVY-7979: Check for single minus in NumberValue

This check is performed at the time of parsing, rather than while
reading the return from `JsonSlurper`. The intent is that the slurper
should, to the best of it's ability, give you a structure which is
valid.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/589846d0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/589846d0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/589846d0

Branch: refs/heads/GROOVY_2_4_X
Commit: 589846d009327d2cc6d5c70f9ae2fb62741b07e0
Parents: 91cd79d
Author: James Laverack <ja...@jameslaverack.com>
Authored: Fri May 26 22:10:44 2017 +0100
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 27 14:22:48 2017 -0700

----------------------------------------------------------------------
 .../src/main/java/groovy/json/internal/NumberValue.java        | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/589846d0/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
index ffa5ffb..5e8e6ca 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
@@ -66,6 +66,12 @@ public class NumberValue extends java.lang.Number implements Value {
         } catch (Exception ex) {
             Exceptions.handle(sputs("exception", ex, "start", startIndex, "end", endIndex), ex);
         }
+
+        // Check for a single minus now, rather than finding out later during lazy parsing.
+        if (this.endIndex - this.startIndex == 1 && this.buffer[this.startIndex] == '-') {
+            die("A single minus is not a valid number");
+        }
+
     }
 
     public String toString() {