@@ -20,19 +20,77 @@ protected JsonFactory jsonFactory() {
20
20
return JSON_F ;
21
21
}
22
22
23
+ /**
24
+ * The format "0xc0ffee" is not valid JSON, so this should fail
25
+ */
26
+ public void testHexadecimal () throws Exception {
27
+ for (int mode : ALL_MODES ) {
28
+ try (JsonParser p = createParser (mode , " 0xc0ffee " )) {
29
+ p .nextToken ();
30
+ fail ("Should not pass" );
31
+ } catch (JsonParseException e ) {
32
+ verifyException (e , "Unexpected character ('x'" );
33
+ }
34
+ }
35
+ }
36
+
37
+ public void testHexadecimalBigX () throws Exception {
38
+ for (int mode : ALL_MODES ) {
39
+ try (JsonParser p = createParser (mode , " 0XC0FFEE " )) {
40
+ p .nextToken ();
41
+ fail ("Should not pass" );
42
+ } catch (JsonParseException e ) {
43
+ verifyException (e , "Unexpected character ('x'" );
44
+ }
45
+ }
46
+ }
47
+
48
+ public void testNegativeHexadecimal () throws Exception {
49
+ for (int mode : ALL_MODES ) {
50
+ try (JsonParser p = createParser (mode , " -0xc0ffee " )) {
51
+ p .nextToken ();
52
+ fail ("Should not pass" );
53
+ } catch (JsonParseException e ) {
54
+ verifyException (e , "Unexpected character ('x'" );
55
+ }
56
+ }
57
+ }
58
+
59
+ //JSON does not allow numbers to have f or d suffixes
60
+ public void testFloatMarker () throws Exception {
61
+ for (int mode : ALL_MODES ) {
62
+ try (JsonParser p = createParser (mode , " -0.123f " )) {
63
+ p .nextToken ();
64
+ fail ("Should not pass" );
65
+ } catch (JsonParseException e ) {
66
+ verifyException (e , "Unexpected character ('f'" );
67
+ }
68
+ }
69
+ }
70
+
71
+ //JSON does not allow numbers to have f or d suffixes
72
+ public void testDoubleMarker () throws Exception {
73
+ for (int mode : ALL_MODES ) {
74
+ try (JsonParser p = createParser (mode , " -0.123d " )) {
75
+ p .nextToken ();
76
+ fail ("Should not pass" );
77
+ } catch (JsonParseException e ) {
78
+ verifyException (e , "Unexpected character ('d'" );
79
+ }
80
+ }
81
+ }
82
+
23
83
/**
24
84
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
25
85
*/
26
86
public void testLeadingDotInDecimal () throws Exception {
27
87
for (int mode : ALL_MODES ) {
28
- JsonParser p = createParser (mode , " .123 " );
29
- try {
88
+ try (JsonParser p = createParser (mode , " .123 " )) {
30
89
p .nextToken ();
31
90
fail ("Should not pass" );
32
91
} catch (JsonParseException e ) {
33
92
verifyException (e , "Unexpected character ('.'" );
34
93
}
35
- p .close ();
36
94
}
37
95
}
38
96
0 commit comments