diff --git a/src/PikaObj.c b/src/PikaObj.c index 53d2facac..954d3deb8 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -1064,9 +1064,18 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) { /* run xx.py.o */ if (inputChar[0] == 'p' && inputChar[1] == 0x7f) { + char yo[2] = {0}; for (int i = 0; i < 2; i++) { /* eat 'yo' */ - cfg->fn_getchar(); + yo[i] = cfg->fn_getchar(); + } + if (!(yo[0] == 'y' && yo[1] == 'o')) { + /* not the magic code, abort */ + _do_obj_runChar(self, 0x7f, cfg); + _do_obj_runChar(self, 'p', cfg); + _do_obj_runChar(self, yo[0], cfg); + _do_obj_runChar(self, yo[1], cfg); + continue; } uint32_t size = 0; for (int i = 0; i < 4; i++) { diff --git a/test/pikaMain-test.cpp b/test/pikaMain-test.cpp index fd2a58ed2..408d5cf52 100644 --- a/test/pikaMain-test.cpp +++ b/test/pikaMain-test.cpp @@ -2755,3 +2755,21 @@ TEST(pikaMain, REPL_backspace_issue_1) { obj_deinit(pikaMain); EXPECT_EQ(pikaMemNow(), 0); } + +TEST(pikaMain, REPL_backspace_issue_2) { + char* lines = + "loop\bp\n"; + /* init */ + pikaMemInfo.heapUsedMax = 0; + PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); + /* run */ + __platform_printf("BEGIN\r\n"); + for (size_t i = 0; i < strGetSize(lines); i++) { + obj_runChar(pikaMain, lines[i]); + } + /* collect */ + /* assert */ + /* deinit */ + obj_deinit(pikaMain); + EXPECT_EQ(pikaMemNow(), 0); +}