reader: Remove assert in history search

This isn't a great use of `assert` because it turns a benign "oh I
need to search again" bug into a crash.

Fixes #9628

(cherry picked from commit 7c91d009c1)
This commit is contained in:
Fabian Boehm 2023-03-02 16:29:49 +01:00
parent 1a20184ba4
commit 37575c5f79

View file

@ -428,8 +428,15 @@ class reader_history_search_t {
const wcstring &needle = search_string();
if (mode_ == line || mode_ == prefix) {
size_t offset = find(text, needle);
assert(offset != wcstring::npos && "Should have found a match in the search result");
add_if_new({std::move(text), offset});
// FIXME: Previous versions asserted out if this wasn't true.
// This could be hit with a needle of "ö" and haystack of "echo Ö"
// I'm not sure why - this points to a bug in ifind (probably wrong locale?)
// However, because the user experience of having it crash is horrible,
// and the worst thing that can otherwise happen here is that a search is unsuccessful,
// we just check it instead.
if (offset != wcstring::npos) {
add_if_new({std::move(text), offset});
}
} else if (mode_ == token) {
tokenizer_t tok(text.c_str(), TOK_ACCEPT_UNFINISHED);