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:32 UTC

[1/4] groovy git commit: GROOVY-7979: Add JSONSlurper test case for the string "[-]".

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 4ea3daf75 -> 61ba432de


GROOVY-7979: Add JSONSlurper test case for the string "[-]".


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

Branch: refs/heads/GROOVY_2_4_X
Commit: fc881b03a8f3e08a94a8a3bc8957c97df11833b5
Parents: 4ea3daf
Author: James Laverack <ja...@jameslaverack.com>
Authored: Sat May 13 13:38:34 2017 +0100
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 27 14:13:03 2017 -0700

----------------------------------------------------------------------
 .../src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy           | 1 +
 .../groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy  | 1 +
 2 files changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/fc881b03/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy
index f19b6a2..ca89ef0 100644
--- a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy
+++ b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperLaxTest.groovy
@@ -37,6 +37,7 @@ class JsonSlurperLaxTest extends JsonSlurperTest {
         shouldFail(JsonException) { parser.parseText('{a"') }
         shouldFail(JsonException) { parser.parseText("[\"a\"") }
         shouldFail(JsonException) { parser.parseText('{"a"') }
+        shouldFail(JsonException) { parser.parseText('[-]') }
     }
 
     void testObjectWithSimpleValues() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/fc881b03/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy
index b8068df..9356825 100644
--- a/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy
+++ b/subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperTest.groovy
@@ -274,6 +274,7 @@ class JsonSlurperTest extends GroovyTestCase {
         shouldFail(JsonException) { parser.parseText('["a"')        }
         shouldFail(JsonException) { parser.parseText('["a", ')      }
         shouldFail(JsonException) { parser.parseText('["a", true')  }
+        shouldFail(JsonException) { parser.parseText('[-]') }
     }
 
     void testBackSlashEscaping() {


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

Posted by jw...@apache.org.
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() {


[2/4] groovy git commit: GROOVY-7979: Add check for end of negative number

Posted by jw...@apache.org.
GROOVY-7979: Add check for end of negative number

The check for the minus sign increments the character index by one. A
check is added to ensure that this does not go over the end of the
expected character substring.


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 91cd79da9d5cc20a9c4b29c135cd57fe93a580a8
Parents: fc881b0
Author: James Laverack <ja...@jameslaverack.com>
Authored: Sun May 14 20:21:43 2017 +0100
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat May 27 14:22:11 2017 -0700

----------------------------------------------------------------------
 .../java/groovy/json/internal/CharScanner.java    | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/91cd79da/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java
index e110943..c7292e5 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharScanner.java
@@ -453,6 +453,9 @@ public class CharScanner {
                 offset++;
                 negative = true;
             }
+            if (offset >= to) {
+                die();
+            }
             if (negative) {
                 num = (digitChars[offset] - '0');
                 if (++offset < to) {
@@ -527,7 +530,9 @@ public class CharScanner {
             offset++;
             negative = true;
         }
-
+        if (offset >= to) {
+            die();
+        }
         c = digitChars[offset];
         num = (c - '0');
         offset++;
@@ -550,7 +555,9 @@ public class CharScanner {
             offset++;
             negative = true;
         }
-
+        if (offset >= to) {
+            die();
+        }
         c = digitChars[offset];
         num = (c - '0');
         offset++;
@@ -573,7 +580,9 @@ public class CharScanner {
             offset++;
             negative = true;
         }
-
+        if (offset >= to) {
+            die();
+        }
         c = digitChars[offset];
         num = (c - '0');
         offset++;
@@ -619,6 +628,9 @@ public class CharScanner {
         if (buffer[index] == '-') {
             index++;
         }
+        if (index >= max) {
+            die();
+        }
 
         boolean foundDot = false;
         for (; index < max; index++) {


[4/4] groovy git commit: Remove pointless sign handling (closes #552)

Posted by jw...@apache.org.
Remove pointless sign handling (closes #552)

This code is useless as both of these code paths ultimately call out to
`CharScanner#parseIntFromTo` which handles the negative sign.


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

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

----------------------------------------------------------------------
 .../java/groovy/json/internal/NumberValue.java     | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/61ba432d/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 5e8e6ca..da98357 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
@@ -110,16 +110,10 @@ public class NumberValue extends java.lang.Number implements Value {
             case DOUBLE:
                 return bigDecimalValue();
             case INTEGER:
-                int sign = 1;
-                if (buffer[startIndex] == '-') {
-                    startIndex++;
-                    sign = -1;
-                }
-
                 if (isInteger(buffer, startIndex, endIndex - startIndex)) {
-                    return intValue() * sign;
+                    return intValue();
                 } else {
-                    return longValue() * sign;
+                    return longValue();
                 }
         }
         die();
@@ -174,12 +168,7 @@ public class NumberValue extends java.lang.Number implements Value {
     }
 
     public int intValue() {
-        int sign = 1;
-        if (buffer[startIndex] == '-') {
-            startIndex++;
-            sign = -1;
-        }
-        return parseIntFromTo(buffer, startIndex, endIndex) * sign;
+        return parseIntFromTo(buffer, startIndex, endIndex);
     }
 
     public long longValue() {