From a7e9ac36123ad66ec4ac9a7dff3197276b55d5d1 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 9 Sep 2011 05:11:59 +0000 Subject: [PATCH] Don't support oversized values like 30-character integers --- gson/GSON 2.0 NOTES.txt | 7 +++++- .../google/gson/functional/PrimitiveTest.java | 24 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gson/GSON 2.0 NOTES.txt b/gson/GSON 2.0 NOTES.txt index f2d771bf..cd8e5fa0 100644 --- a/gson/GSON 2.0 NOTES.txt +++ b/gson/GSON 2.0 NOTES.txt @@ -20,4 +20,9 @@ com.google.gson.functional.PrimitiveTest.testOverridingDefaultPrimitiveSerializa GSON 1.x rejects integers that have any fraction, even if it is ".0" GSON 2.x permits integers to have ".0" fractions like "1.0" -com.google.gson.functional.PrimitiveTest.testDeserializingDecimalPointValuesAsIntegerFails \ No newline at end of file +com.google.gson.functional.PrimitiveTest.testDeserializingDecimalPointValuesAsIntegerFails + +GSON 1.x truncates oversized large integers and longs +GSON 2.x fails on oversized large integers and longs +com.google.gson.functional.PrimitiveTest.testDeserializingBigIntegerAsInteger +com.google.gson.functional.PrimitiveTest.testDeserializingBigIntegerAsLong \ No newline at end of file diff --git a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java index 65d080d5..7ffdb227 100644 --- a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java +++ b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java @@ -18,18 +18,14 @@ package com.google.gson.functional; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import com.google.gson.LongSerializationPolicy; -import com.google.gson.common.TestTypes.CrazyLongTypeAdapter; - -import junit.framework.TestCase; - import java.io.Serializable; import java.io.StringReader; import java.math.BigDecimal; import java.math.BigInteger; +import junit.framework.TestCase; /** * Functional tests for Json primitive values: integers, and floating point numbers. @@ -748,17 +744,19 @@ public class PrimitiveTest extends TestCase { } public void testDeserializingBigIntegerAsInteger() { - String bigIntegerValue = "12121211243123245845384534687435634558945453489543985435"; - int actual = gson.fromJson(bigIntegerValue, Integer.class); - int expected = new BigInteger(bigIntegerValue).and(MAX_INT_VALUE).intValue(); - assertEquals(expected, actual); + try { + gson.fromJson("12121211243123245845384534687435634558945453489543985435", Integer.class); + fail(); + } catch (JsonSyntaxException expected) { + } } public void testDeserializingBigIntegerAsLong() { - String bigIntegerValue = "12121211243123245845384534687435634558945453489543985435"; - long actual = gson.fromJson(bigIntegerValue, long.class); - long expected = new BigInteger(bigIntegerValue).and(MAX_LONG_VALUE).longValue(); - assertEquals(expected, actual); + try { + gson.fromJson("12121211243123245845384534687435634558945453489543985435", Long.class); + fail(); + } catch (JsonSyntaxException expected) { + } } public void testDeserializingBigDecimalAsLongFails() {