Skip to content

Commit 7231ca3

Browse files
tokangasrlubos
authored andcommitted
samples: cellular: modem_shell: Fix handling of quotes with backspace
If the character removed using backspace was a quote, the internal state of the RX handler was not updated correctly. This caused incorrect behavior when handling the following characters. Signed-off-by: Tommi Kangas <[email protected]>
1 parent d28462c commit 7231ca3

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

samples/cellular/modem_shell/src/at/at_cmd_mode.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,23 @@ static void at_cmd_mode_cmd_rx_handler(uint8_t character)
127127
case 0x08: /* Backspace. */
128128
/* Fall through. */
129129
case 0x7F: /* DEL character */
130-
if (at_cmd_len > 0) {
131-
/* Reprint with DEL/Backspace */
132-
k_mutex_lock(&at_buf_mutex, K_FOREVER);
133-
at_buf[at_cmd_len] = '\0';
134-
at_cmd_len--;
135-
at_buf[at_cmd_len] = ' ';
136-
printk("\r%s", at_buf);
137-
at_buf[at_cmd_len] = '\0';
138-
printk("\r%s", at_buf);
139-
k_mutex_unlock(&at_buf_mutex);
130+
if (at_cmd_len == 0) {
131+
return;
140132
}
133+
134+
/* Reprint with DEL/Backspace */
135+
k_mutex_lock(&at_buf_mutex, K_FOREVER);
136+
at_buf[at_cmd_len] = '\0';
137+
at_cmd_len--;
138+
/* If the removed character was a quote, need to toggle the flag. */
139+
if (at_buf[at_cmd_len] == '"') {
140+
inside_quotes = !inside_quotes;
141+
}
142+
at_buf[at_cmd_len] = ' ';
143+
printk("\r%s", at_buf);
144+
at_buf[at_cmd_len] = '\0';
145+
printk("\r%s", at_buf);
146+
k_mutex_unlock(&at_buf_mutex);
141147
return;
142148
}
143149

0 commit comments

Comments
 (0)