Skip to content

Commit

Permalink
negative zero test and fix (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleumik authored and inder123 committed Apr 19, 2017
1 parent 41e48f7 commit 9a24219
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gson/src/main/java/com/google/gson/stream/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ private int peekNumber() throws IOException {
}

// We've read a complete number. Decide if it's a PEEKED_LONG or a PEEKED_NUMBER.
if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative)) {
if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative) && (value!=0 || false==negative)) {
peekedLong = negative ? value : -value;
pos += i;
return peeked = PEEKED_LONG;
Expand Down
12 changes: 12 additions & 0 deletions gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ public void testLongLargerThanMinLongThatWrapsAround() throws IOException {
} catch (NumberFormatException expected) {
}
}

/**
* Issue 1053, negative zero.
* @throws Exception
*/
public void testNegativeZero() throws Exception {
JsonReader reader = new JsonReader(reader("[-0]"));
reader.setLenient(false);
reader.beginArray();
assertEquals(NUMBER, reader.peek());
assertEquals("-0", reader.nextString());
}

/**
* This test fails because there's no double for 9223372036854775808, and our
Expand Down

0 comments on commit 9a24219

Please sign in to comment.