Skip to content

Commit 9a24219

Browse files
eleumikinder123
authored andcommitted
negative zero test and fix (#1069)
1 parent 41e48f7 commit 9a24219

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

gson/src/main/java/com/google/gson/stream/JsonReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ private int peekNumber() throws IOException {
728728
}
729729

730730
// We've read a complete number. Decide if it's a PEEKED_LONG or a PEEKED_NUMBER.
731-
if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative)) {
731+
if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative) && (value!=0 || false==negative)) {
732732
peekedLong = negative ? value : -value;
733733
pos += i;
734734
return peeked = PEEKED_LONG;

gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,18 @@ public void testLongLargerThanMinLongThatWrapsAround() throws IOException {
560560
} catch (NumberFormatException expected) {
561561
}
562562
}
563+
564+
/**
565+
* Issue 1053, negative zero.
566+
* @throws Exception
567+
*/
568+
public void testNegativeZero() throws Exception {
569+
JsonReader reader = new JsonReader(reader("[-0]"));
570+
reader.setLenient(false);
571+
reader.beginArray();
572+
assertEquals(NUMBER, reader.peek());
573+
assertEquals("-0", reader.nextString());
574+
}
563575

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

0 commit comments

Comments
 (0)