diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index cd08f2759c..4dfee8ec35 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -1063,6 +1063,27 @@ TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag) ATHandler at(&fh1, que, 0, ","); EXPECT_TRUE(at.consume_to_stop_tag()); + + at.clear_error(); + char table1[] = "\r\n\r\r\r\nOOK\r\n"; + at.flush(); + filehandle_stub_table = table1; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf1[6]; + at.resp_start(); + EXPECT_TRUE(at.consume_to_stop_tag()); + + at.clear_error(); + char table2[] = "OKOK\r\n"; + at.flush(); + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf2[6]; + EXPECT_TRUE(at.consume_to_stop_tag()); } TEST_F(TestATHandler, test_ATHandler_set_debug) diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index d9de60f4f9..ccbe47fce1 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -943,7 +943,9 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag) int c = get_char(); if (c == -1) { break; - } else if (c == tag[match_pos]) { + // compares c against tag at current position and if this match fails + // compares c against tag[0] and also resets match_pos to 0 + } else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) { match_pos++; if (match_pos == strlen(tag)) { if (!consume_tag) { @@ -951,8 +953,6 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag) } return true; } - } else if (match_pos) { - match_pos = 0; } } tr_debug("consume_to_tag not found");