File tree 2 files changed +59
-1
lines changed
main/java/org/codehaus/jettison/json
test/java/org/codehaus/jettison/json
2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,9 @@ public char nextClean() throws JSONException {
197
197
}
198
198
break ;
199
199
default :
200
+ if (!more ()) {
201
+ throw syntaxError ("The JSON text is malformed" );
202
+ }
200
203
back ();
201
204
return '/' ;
202
205
}
Original file line number Diff line number Diff line change @@ -92,5 +92,60 @@ public void testForwardSlashEscapingModifiedfBySetter() throws Exception {
92
92
assertEquals (obj .toString (), "{\" key\" :\" http://example.com/foo\" }" );
93
93
obj .setEscapeForwardSlashAlways (true );
94
94
assertEquals (obj .toString (), "{\" key\" :\" http:\\ /\\ /example.com\\ /foo\" }" );
95
- }
95
+ }
96
+
97
+ public void testMalformedObject () throws Exception {
98
+ try {
99
+ new JSONObject ("{/" );
100
+ fail ("Failure expected on malformed JSON" );
101
+ } catch (JSONException ex ) {
102
+ // expected
103
+ }
104
+ }
105
+
106
+ public void testMalformedObject2 () throws Exception {
107
+ try {
108
+ new JSONObject ("{x" );
109
+ fail ("Failure expected on malformed JSON" );
110
+ } catch (JSONException ex ) {
111
+ // expected
112
+ }
113
+ }
114
+
115
+ public void testMalformedObject3 () throws Exception {
116
+ try {
117
+ new JSONObject ("{/x" );
118
+ fail ("Failure expected on malformed JSON" );
119
+ } catch (JSONException ex ) {
120
+ // expected
121
+ }
122
+ }
123
+
124
+ public void testMalformedObject4 () throws Exception {
125
+ try {
126
+ new JSONObject ("{/*" );
127
+ fail ("Failure expected on malformed JSON" );
128
+ } catch (JSONException ex ) {
129
+ // expected
130
+ }
131
+ }
132
+
133
+ public void testMalformedObject5 () throws Exception {
134
+ try {
135
+ new JSONObject ("{//" );
136
+ fail ("Failure expected on malformed JSON" );
137
+ } catch (JSONException ex ) {
138
+ // expected
139
+ }
140
+ }
141
+
142
+ public void testMalformedArray () throws Exception {
143
+ try {
144
+ new JSONObject ("{[/" );
145
+ fail ("Failure expected on malformed JSON" );
146
+ } catch (JSONException ex ) {
147
+ // expected
148
+ }
149
+ }
150
+
96
151
}
You can’t perform that action at this time.
0 commit comments