diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index faa4c78399..d5bbc02068 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -348,6 +348,7 @@ std::string UnescapeMenuString(const char *input, char *shortcutChar) { std::string output; output.reserve(len); bool escaping = false; + bool escapeFound = false; for (size_t i = 0; i < len; i++) { if (input[i] == '&') { if (escaping) { @@ -358,8 +359,9 @@ std::string UnescapeMenuString(const char *input, char *shortcutChar) { } } else { output.push_back(input[i]); - if (escaping && shortcutChar) { + if (escaping && shortcutChar && !escapeFound) { *shortcutChar = input[i]; + escapeFound = true; } escaping = false; } diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index b038bdb878..605ba0bfb8 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -908,6 +908,9 @@ bool TestEscapeMenuString() { EXPECT_EQ_STR(temp, std::string("Edit")); temp = UnescapeMenuString("Cut && Paste", nullptr); EXPECT_EQ_STR(temp, std::string("Cut & Paste")); + temp = UnescapeMenuString("&A&B", &c); + EXPECT_EQ_STR(temp, std::string("AB")); + EXPECT_EQ_INT((int)c, (int)'A'); return true; }