@@ -870,7 +870,7 @@ _bson_json_parse_binary_elem (bson_json_reader_t *reader,
870870
871871 if (bs == BSON_JSON_LF_BINARY ) {
872872 data -> binary .has_binary = true;
873- binary_len = COMMON_PREFIX ( bson_b64_pton ( val_w_null , NULL , 0 ) );
873+ binary_len = mcommon_b64_pton ( val_w_null , NULL , 0 );
874874 if (binary_len < 0 ) {
875875 _bson_json_read_set_error (
876876 reader ,
@@ -879,9 +879,9 @@ _bson_json_parse_binary_elem (bson_json_reader_t *reader,
879879 }
880880
881881 _bson_json_buf_ensure (& bson -> bson_type_buf [0 ], (size_t ) binary_len + 1 );
882- if (COMMON_PREFIX ( bson_b64_pton (val_w_null ,
883- bson -> bson_type_buf [0 ].buf ,
884- (size_t ) binary_len + 1 ) < 0 ) ) {
882+ if (mcommon_b64_pton (val_w_null ,
883+ bson -> bson_type_buf [0 ].buf ,
884+ (size_t ) binary_len + 1 ) < 0 ) {
885885 _bson_json_read_set_error (
886886 reader ,
887887 "Invalid input string \"%s\", looking for base64-encoded binary" ,
@@ -1178,18 +1178,59 @@ _bson_json_read_start_map (bson_json_reader_t *reader) /* IN */
11781178 BASIC_CB_PREAMBLE ;
11791179
11801180 if (bson -> read_state == BSON_JSON_IN_BSON_TYPE ) {
1181- if (bson -> bson_state == BSON_JSON_LF_DATE ) {
1181+ switch (bson -> bson_state ) {
1182+ case BSON_JSON_LF_DATE :
11821183 bson -> read_state = BSON_JSON_IN_BSON_TYPE_DATE_NUMBERLONG ;
1183- } else if (bson -> bson_state == BSON_JSON_LF_BINARY ) {
1184+ break ;
1185+ case BSON_JSON_LF_BINARY :
11841186 bson -> read_state = BSON_JSON_IN_BSON_TYPE_BINARY_VALUES ;
1185- } else if (bson -> bson_state == BSON_JSON_LF_TYPE ) {
1187+ break ;
1188+ case BSON_JSON_LF_TYPE :
11861189 /* special case, we started parsing {$type: {$numberInt: "2"}} and we
11871190 * expected a legacy Binary format. now we see the second "{", so
11881191 * backtrack and parse $type query operator. */
11891192 bson -> read_state = BSON_JSON_IN_START_MAP ;
11901193 STACK_PUSH_DOC (bson_append_document_begin (
11911194 STACK_BSON_PARENT , key , len , STACK_BSON_CHILD ));
11921195 _bson_json_save_map_key (bson , (const uint8_t * ) "$type" , 5 );
1196+ break ;
1197+ case BSON_JSON_LF_CODE :
1198+ case BSON_JSON_LF_DECIMAL128 :
1199+ case BSON_JSON_LF_DOUBLE :
1200+ case BSON_JSON_LF_INT32 :
1201+ case BSON_JSON_LF_INT64 :
1202+ case BSON_JSON_LF_MAXKEY :
1203+ case BSON_JSON_LF_MINKEY :
1204+ case BSON_JSON_LF_OID :
1205+ case BSON_JSON_LF_OPTIONS :
1206+ case BSON_JSON_LF_REGEX :
1207+ /**
1208+ * NOTE: A read_state of BSON_JSON_IN_BSON_TYPE is used when "$regex" is
1209+ * found, but BSON_JSON_IN_BSON_TYPE_REGEX_STARTMAP is used for
1210+ * "$regularExpression", which will instead go to a below 'if else' branch
1211+ * instead of this switch statement. They're both called "regex" in their
1212+ * respective enumerators, but they behave differently when parsing.
1213+ */
1214+ // fallthrough
1215+ case BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS :
1216+ case BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN :
1217+ case BSON_JSON_LF_SYMBOL :
1218+ case BSON_JSON_LF_UNDEFINED :
1219+ case BSON_JSON_LF_UUID :
1220+ // These special keys do not expect objects as their values. Fail.
1221+ _bson_json_read_set_error (
1222+ reader ,
1223+ "Unexpected nested object value for \"%s\" key" ,
1224+ reader -> bson .unescaped .buf );
1225+ break ;
1226+ case BSON_JSON_LF_DBPOINTER :
1227+ case BSON_JSON_LF_SCOPE :
1228+ case BSON_JSON_LF_TIMESTAMP_I :
1229+ case BSON_JSON_LF_TIMESTAMP_T :
1230+ default :
1231+ // These special LF keys aren't handled with BSON_JSON_IN_BSON_TYPE
1232+ BSON_UNREACHABLE (
1233+ "These LF values are handled with a different read_state" );
11931234 }
11941235 } else if (bson -> read_state == BSON_JSON_IN_BSON_TYPE_TIMESTAMP_STARTMAP ) {
11951236 bson -> read_state = BSON_JSON_IN_BSON_TYPE_TIMESTAMP_VALUES ;
0 commit comments