mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19: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.
|
// 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;
|
peekedLong = negative ? value : -value;
|
||||||
buffer.skip(i);
|
buffer.skip(i);
|
||||||
return peeked = PEEKED_LONG;
|
return peeked = PEEKED_LONG;
|
||||||
|
@@ -330,6 +330,12 @@ public final class JsonUtf8ReaderTest {
|
|||||||
assertThat(reader.nextDouble()).isEqualTo(-92233720368547758080d);
|
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 {
|
@Test public void quotedNumberWithEscape() throws IOException {
|
||||||
JsonReader reader = newReader("[\"12\u00334\"]");
|
JsonReader reader = newReader("[\"12\u00334\"]");
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
|
Reference in New Issue
Block a user