Mercurial > hg > batmud > maputils
changeset 1908:a52f3b18b0bf
Trim location search query string.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Nov 2017 14:33:08 +0200 |
parents | 20f0acd6f962 |
children | 8002da562785 |
files | mapsearch.c |
diffstat | 1 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mapsearch.c Mon Nov 06 12:22:47 2017 +0200 +++ b/mapsearch.c Mon Nov 06 14:33:08 2017 +0200 @@ -1109,24 +1109,31 @@ { MAPMatch matches[SET_MAX_MATCHES]; int nmatches = 0; - char *pattern = NULL; + char *pattern = NULL, *stmp; + size_t offs1, offs2, slen; // Check search pattern length - if (len < 3) + for (offs1 = 0; offs1 < len && th_isspace(data[offs1]); ) offs1++; + for (offs2 = len; offs2 > offs1 && (data[offs2] == 0 || th_isspace(data[offs2])); ) offs2--; + + slen = offs2 - offs1 + 1; + if (slen < 3) { *verr = "Search pattern too short."; goto out; } - if (len > 25) + if (slen > 25) { *verr = "Search pattern too long."; goto out; } - char *tmp = th_strndup((char *) data, len); - pattern = th_strdup_printf("*%s*", tmp); - th_free(tmp); + stmp = th_strndup((char *) data + offs1, slen); + pattern = th_strdup_printf("*%s*", stmp); + th_free(stmp); + + mapMSG(2, "Search pattern: '%s'\n", pattern); // // Search the maps .. enabled or if none specified, all of them @@ -1247,7 +1254,7 @@ { mapMSG(1, "[%p] Location search query.\n", wsi); - if (len <= 10 + 1) + if (len <= 10) verr = "Invalid search query."; else mapLocationSearch(wsi, udata + 10, len - 10, &verr);