Commit 4dba3c95dd9cc721957f8138fe19ab2872328f27
1 parent
6f94a3a8
In JSONParser::handleToken move validation for ls_colon etc into switch statement
Showing
1 changed file
with
35 additions
and
36 deletions
libqpdf/JSON.cc
| @@ -1150,10 +1150,44 @@ JSONParser::handleToken() | @@ -1150,10 +1150,44 @@ JSONParser::handleToken() | ||
| 1150 | break; | 1150 | break; |
| 1151 | 1151 | ||
| 1152 | case ls_colon: | 1152 | case ls_colon: |
| 1153 | + if (parser_state != ps_dict_after_key) { | ||
| 1154 | + QTC::TC("libtests", "JSON parse unexpected :"); | ||
| 1155 | + throw std::runtime_error( | ||
| 1156 | + "JSON: offset " + std::to_string(offset) + | ||
| 1157 | + ": unexpected colon"); | ||
| 1158 | + } | ||
| 1159 | + break; | ||
| 1160 | + | ||
| 1153 | case ls_comma: | 1161 | case ls_comma: |
| 1162 | + if (!((parser_state == ps_dict_after_item) || | ||
| 1163 | + (parser_state == ps_array_after_item))) { | ||
| 1164 | + QTC::TC("libtests", "JSON parse unexpected ,"); | ||
| 1165 | + throw std::runtime_error( | ||
| 1166 | + "JSON: offset " + std::to_string(offset) + | ||
| 1167 | + ": unexpected comma"); | ||
| 1168 | + } | ||
| 1169 | + break; | ||
| 1170 | + | ||
| 1154 | case ls_end_array: | 1171 | case ls_end_array: |
| 1172 | + if (!((parser_state == ps_array_begin) || | ||
| 1173 | + (parser_state == ps_array_after_item))) | ||
| 1174 | + | ||
| 1175 | + { | ||
| 1176 | + QTC::TC("libtests", "JSON parse unexpected ]"); | ||
| 1177 | + throw std::runtime_error( | ||
| 1178 | + "JSON: offset " + std::to_string(offset) + | ||
| 1179 | + ": unexpected array end delimiter"); | ||
| 1180 | + } | ||
| 1181 | + break; | ||
| 1182 | + | ||
| 1155 | case ls_end_dict: | 1183 | case ls_end_dict: |
| 1156 | - // continue | 1184 | + if (!((parser_state == ps_dict_begin) || |
| 1185 | + (parser_state == ps_dict_after_item))) { | ||
| 1186 | + QTC::TC("libtests", "JSON parse unexpected }"); | ||
| 1187 | + throw std::runtime_error( | ||
| 1188 | + "JSON: offset " + std::to_string(offset) + | ||
| 1189 | + ": unexpected dictionary end delimiter"); | ||
| 1190 | + } | ||
| 1157 | break; | 1191 | break; |
| 1158 | 1192 | ||
| 1159 | case ls_number: | 1193 | case ls_number: |
| @@ -1235,41 +1269,6 @@ JSONParser::handleToken() | @@ -1235,41 +1269,6 @@ JSONParser::handleToken() | ||
| 1235 | break; | 1269 | break; |
| 1236 | // okay | 1270 | // okay |
| 1237 | } | 1271 | } |
| 1238 | - } else if (lex_state == ls_end_dict) { | ||
| 1239 | - if (!((parser_state == ps_dict_begin) || | ||
| 1240 | - (parser_state == ps_dict_after_item))) | ||
| 1241 | - | ||
| 1242 | - { | ||
| 1243 | - QTC::TC("libtests", "JSON parse unexpected }"); | ||
| 1244 | - throw std::runtime_error( | ||
| 1245 | - "JSON: offset " + std::to_string(offset) + | ||
| 1246 | - ": unexpected dictionary end delimiter"); | ||
| 1247 | - } | ||
| 1248 | - } else if (lex_state == ls_end_array) { | ||
| 1249 | - if (!((parser_state == ps_array_begin) || | ||
| 1250 | - (parser_state == ps_array_after_item))) | ||
| 1251 | - | ||
| 1252 | - { | ||
| 1253 | - QTC::TC("libtests", "JSON parse unexpected ]"); | ||
| 1254 | - throw std::runtime_error( | ||
| 1255 | - "JSON: offset " + std::to_string(offset) + | ||
| 1256 | - ": unexpected array end delimiter"); | ||
| 1257 | - } | ||
| 1258 | - } else if (lex_state == ls_colon) { | ||
| 1259 | - if (parser_state != ps_dict_after_key) { | ||
| 1260 | - QTC::TC("libtests", "JSON parse unexpected :"); | ||
| 1261 | - throw std::runtime_error( | ||
| 1262 | - "JSON: offset " + std::to_string(offset) + | ||
| 1263 | - ": unexpected colon"); | ||
| 1264 | - } | ||
| 1265 | - } else if (lex_state == ls_comma) { | ||
| 1266 | - if (!((parser_state == ps_dict_after_item) || | ||
| 1267 | - (parser_state == ps_array_after_item))) { | ||
| 1268 | - QTC::TC("libtests", "JSON parse unexpected ,"); | ||
| 1269 | - throw std::runtime_error( | ||
| 1270 | - "JSON: offset " + std::to_string(offset) + | ||
| 1271 | - ": unexpected comma"); | ||
| 1272 | - } | ||
| 1273 | } | 1272 | } |
| 1274 | 1273 | ||
| 1275 | // Now we know we have a delimiter or item that is allowed. Do | 1274 | // Now we know we have a delimiter or item that is allowed. Do |