>From 10e65f4f8c1016ce90d6e0d159c78ca642d4bba3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Dufberg=20T=C3=B8ttrup?= <[email protected]>
Date: Sat, 20 Aug 2016 16:20:19 +0200
Subject: [PATCH] Fix prefix match is treated as exact match
Input text and items are only compared up to length of input but should be
compared against the full length of the item.
---
dmenu.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index 3b05752..ad3a2f1 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -198,7 +198,7 @@ match(void)
char buf[sizeof text], *s;
int i, tokc = 0;
- size_t len, textsize;
+ size_t len, itemlen;
struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
strcpy(buf, text);
@@ -209,15 +209,16 @@ match(void)
len = tokc ? strlen(tokv[0]) : 0;
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
- textsize = strlen(text);
for (item = items; item && item->text; item++) {
for (i = 0; i < tokc; i++)
if (!fstrstr(item->text, tokv[i]))
break;
if (i != tokc) /* not all tokens match */
continue;
+
+ itemlen = strlen(item->text);
/* exact matches go first, then prefixes, then substrings */
- if (!tokc || !fstrncmp(text, item->text, textsize))
+ if (!tokc || !fstrncmp(text, item->text, itemlen))
appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend);
--
2.7.4