[jayrock] push by azizatif - Fixed NumberImporter to disallow converting JSON null to a number on 2011-04-26 23:59 GMT

1 view
Skip to first unread message

jay...@googlecode.com

unread,
Apr 26, 2011, 8:00:40 PM4/26/11
to jayrock...@googlegroups.com
Revision: 497879c1961b
Author: azizatif
Date: Sun Apr 24 07:34:49 2011
Log: Fixed NumberImporter to disallow converting JSON null to a number
http://code.google.com/p/jayrock/source/detail?r=497879c1961b

Modified:
/src/Jayrock.Json/Json/Conversion/Converters/NumberImporter.cs
/tests/Jayrock/Json/Conversion/Converters/TestNumberImporter.cs

=======================================
--- /src/Jayrock.Json/Json/Conversion/Converters/NumberImporter.cs Tue Apr
19 14:01:08 2011
+++ /src/Jayrock.Json/Json/Conversion/Converters/NumberImporter.cs Sun Apr
24 07:34:49 2011
@@ -33,6 +33,11 @@
{
protected NumberImporterBase(Type type) :
base(type) {}
+
+ protected override object ImportNull(ImportContext context,
JsonReader reader)
+ {
+ throw new JsonException(string.Format("JSON null cannot be
imported as {0}.", OutputType.FullName));
+ }

protected override object ImportFromString(ImportContext context,
JsonReader reader)
{
=======================================
--- /tests/Jayrock/Json/Conversion/Converters/TestNumberImporter.cs Fri Apr
15 16:09:54 2011
+++ /tests/Jayrock/Json/Conversion/Converters/TestNumberImporter.cs Sun Apr
24 07:34:49 2011
@@ -84,7 +84,7 @@

#if !NET_1_0 && !NET_1_1 && !NET_2_0

- [Test]
+ [ Test ]
public void ImportBigInteger()
{
AssertImport(System.Numerics.BigInteger.Pow(long.MaxValue,
3), "784637716923335095224261902710254454442933591094742482943");
@@ -92,7 +92,7 @@

#endif // !NET_1_0 && !NET_1_1 && !NET_2_0

- [Test]
+ [ Test ]
public void ImportDecimalUsingExponentialNotation()
{
//
@@ -102,6 +102,14 @@

AssertImport(7.25e-5m, "7.25e-005");
}
+
+ [ Test, ExpectedException(typeof(JsonException)) ]
+ public void CannotImportNull()
+ {
+ ImportContext importContext = new ImportContext();
+ JsonTextReader reader = new JsonTextReader(new
StringReader("null"));
+ new Int32Importer().Import(importContext, reader);
+ }

private static void AssertImport(object expected, string input)
{

Reply all
Reply to author
Forward
0 new messages