This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
tests/ServiceStack.Text.Tests/JsonTests Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ public string Child(string key)
117
117
return base [ key ] ;
118
118
}
119
119
120
- static readonly Regex NumberRegEx = new Regex ( @"^[0 -9]*(?:\.[0-9]*)?$" , PclExport . Instance . RegexOptions ) ;
120
+ static readonly Regex NumberRegEx = new Regex ( @"^(0|[1 -9]*) (?:\.[0-9]*)?$" , PclExport . Instance . RegexOptions ) ;
121
121
122
122
/// <summary>
123
123
/// Write JSON Array, Object, bool or number values as raw string
Original file line number Diff line number Diff line change @@ -26,6 +26,27 @@ public void Can_parse_empty_object_with_mixed_whitespaces()
26
26
Assert . That ( JsonObject . Parse ( "{ \n \t \n \r }" ) , Is . Empty ) ;
27
27
}
28
28
29
+ [ Test ]
30
+ public void Can_Serialize_numbers ( )
31
+ {
32
+ string notNumber = "{\" field\" :\" 00001\" }" ;
33
+ Assert . AreEqual ( notNumber , JsonObject . Parse ( notNumber ) . ToJson < JsonObject > ( ) ) ;
34
+
35
+ string num1 = "{\" field\" :0}" ;
36
+ Assert . AreEqual ( num1 , JsonObject . Parse ( num1 ) . ToJson < JsonObject > ( ) ) ;
37
+
38
+ string num2 = "{\" field\" :0.5}" ;
39
+ Assert . AreEqual ( num2 , JsonObject . Parse ( num2 ) . ToJson < JsonObject > ( ) ) ;
40
+
41
+ string num3 = "{\" field\" :.5}" ;
42
+ Assert . AreEqual ( num3 , JsonObject . Parse ( num3 ) . ToJson < JsonObject > ( ) ) ;
43
+
44
+ string num4 = "{\" field\" :12312}" ;
45
+ Assert . AreEqual ( num4 , JsonObject . Parse ( num4 ) . ToJson < JsonObject > ( ) ) ;
46
+
47
+ string num5 = "{\" field\" :12312.1231}" ;
48
+ Assert . AreEqual ( num5 , JsonObject . Parse ( num5 ) . ToJson < JsonObject > ( ) ) ;
49
+ }
29
50
30
51
public class Jackalope
31
52
{
You can’t perform that action at this time.
0 commit comments