mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Treat negative zero as a number, not a long. (#285)
Updates logic from https://github.com/google/gson/issues/1053
This commit is contained in:
committed by
Jesse Wilson
parent
b4c43ae771
commit
448a2d3298
@@ -464,7 +464,8 @@ final class JsonUtf8Reader extends JsonReader {
|
||||
}
|
||||
|
||||
// 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 || !negative)) {
|
||||
peekedLong = negative ? value : -value;
|
||||
buffer.skip(i);
|
||||
return peeked = PEEKED_LONG;
|
||||
|
@@ -330,6 +330,12 @@ public final class JsonUtf8ReaderTest {
|
||||
assertThat(reader.nextDouble()).isEqualTo(-92233720368547758080d);
|
||||
}
|
||||
|
||||
@Test public void negativeZeroIsANumber() throws Exception {
|
||||
JsonReader reader = newReader("-0");
|
||||
assertEquals(NUMBER, reader.peek());
|
||||
assertEquals("-0", reader.nextString());
|
||||
}
|
||||
|
||||
@Test public void quotedNumberWithEscape() throws IOException {
|
||||
JsonReader reader = newReader("[\"12\u00334\"]");
|
||||
reader.setLenient(true);
|
||||
|
Reference in New Issue
Block a user