[string] Match everything with an empty pattern and -e

I.e. `string match --entire "" -- banana` used to match nothing, now
it matches everything.

Fixes #4971.
This commit is contained in:
Fabian Homborg
2018-09-16 13:03:15 +02:00
parent d44c21b580
commit 3ba74b3195
4 changed files with 13 additions and 1 deletions

View File

@@ -628,7 +628,8 @@ class wildcard_matcher_t : public string_matcher_t {
wcpattern[i] = towlower(wcpattern[i]);
}
}
if (opts.entire && !wcpattern.empty()) {
if (opts.entire) {
// If the pattern is empty, this becomes one ANY_STRING that matches everything.
if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING);
if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING);
}