negative zero test and fix (#1069)

This commit is contained in:
Michele Vivoda 2017-04-19 23:26:36 +02:00 committed by inder123
parent 41e48f7aa3
commit 9a2421997e
2 changed files with 13 additions and 1 deletions

View File

@ -728,7 +728,7 @@ public class JsonReader implements Closeable {
}
// 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;

View File

@ -560,6 +560,18 @@ public final class JsonReaderTest extends TestCase {
} 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