@@ -378,10 +378,11 @@ namespace crow
378378 char * ret = get (name);
379379 if (ret != nullptr )
380380 {
381+ const std::string key_name = name + ' =' ;
381382 for (unsigned int i = 0 ; i < key_value_pairs_.size (); i++)
382383 {
383384 std::string str_item (key_value_pairs_[i]);
384- if (str_item.substr ( 0 , name. size () + 1 ) == name + ' = ' )
385+ if (str_item.find (key_name)== 0 )
385386 {
386387 key_value_pairs_.erase (key_value_pairs_.begin () + i);
387388 break ;
@@ -416,14 +417,18 @@ namespace crow
416417 std::vector<char *> pop_list (const std::string& name, bool use_brackets = true )
417418 {
418419 std::vector<char *> ret = get_list (name, use_brackets);
420+ const size_t name_len = name.length ();
419421 if (!ret.empty ())
420422 {
421423 for (unsigned int i = 0 ; i < key_value_pairs_.size (); i++)
422424 {
423425 std::string str_item (key_value_pairs_[i]);
424- if ((use_brackets ? ( str_item.substr ( 0 , name. size () + 3 ) == name + " []= " ) : (str_item. substr ( 0 , name. size () + 1 ) == name + ' = ' )))
425- {
426+ if (str_item.find ( name)== 0 ) {
427+ if (use_brackets && str_item. find ( " []= " ,name_len)==name_len) {
426428 key_value_pairs_.erase (key_value_pairs_.begin () + i--);
429+ } else if (!use_brackets && str_item.find (' =' ,name_len)==name_len ) {
430+ key_value_pairs_.erase (key_value_pairs_.begin () + i--);
431+ }
427432 }
428433 }
429434 }
@@ -454,13 +459,14 @@ namespace crow
454459 // / Works the same as \ref get_dict() but removes the values from the query string.
455460 std::unordered_map<std::string, std::string> pop_dict (const std::string& name)
456461 {
462+ const std::string name_value = name +' [' ;
457463 std::unordered_map<std::string, std::string> ret = get_dict (name);
458464 if (!ret.empty ())
459465 {
460466 for (unsigned int i = 0 ; i < key_value_pairs_.size (); i++)
461467 {
462468 std::string str_item (key_value_pairs_[i]);
463- if (str_item.substr ( 0 , name. size () + 1 ) == name + ' [ ' )
469+ if (str_item.find (name_value)== 0 )
464470 {
465471 key_value_pairs_.erase (key_value_pairs_.begin () + i--);
466472 }
0 commit comments