Mercurial > projects > pwm
changeset 37:e027dd4409c7
Handle empty fields correctly when filtering the list of entries
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Thu, 08 Aug 2019 10:31:06 +0200 |
parents | f9501248b6bd |
children | 8b55f7b1c6b3 |
files | cmd.c |
diffstat | 1 files changed, 22 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd.c Wed Aug 07 11:28:07 2019 +0200 +++ b/cmd.c Thu Aug 08 10:31:06 2019 +0200 @@ -426,6 +426,11 @@ struct pager *pager = NULL; union list_item **list = NULL; size_t j; + const char *group; + const char *title; + const char *username; + const char *notes; + const char *url; struct record *record; for (i = 1; i < argc; i++) { @@ -482,16 +487,23 @@ pager_printf(pager, "[%s]\n", list[j]->group.group); } else { record = pwfile_get_record(ctx, list[j]->record.id); - if (((group_re == NULL) || (regexec(group_re, - record->group, 0, NULL, 0) == 0)) && - ((title_re == NULL) || (regexec(title_re, - record->title, 0, NULL, 0) == 0)) && - ((username_re == NULL) || (regexec(username_re, - record->username, 0, NULL, 0) == 0)) && - ((notes_re == NULL) || (regexec(notes_re, - record->notes, 0, NULL, 0) == 0)) && - ((url_re == NULL) || (regexec(url_re, - record->url, 0, NULL, 0) == 0))) { + group = (record->group != NULL) ? record->group : ""; + title = (record->title != NULL) ? record->title : ""; + username = (record->username != NULL) ? + record->username : ""; + notes = (record->notes != NULL) ? record->notes : ""; + url = (record->url != NULL) ? record->url : ""; + if (((group_re == NULL) || + (regexec(group_re, group, 0, NULL, 0) == 0)) && + ((title_re == NULL) || + (regexec(title_re, title, 0, NULL, 0) == 0)) && + ((username_re == NULL) || + (regexec(username_re, username, 0, NULL, + 0) == 0)) && + ((notes_re == NULL) || + (regexec(notes_re, notes, 0, NULL, 0) == 0)) && + ((url_re == NULL) || + (regexec(url_re, url, 0, NULL, 0) == 0))) { pager_printf(pager, "%4u %s\n", list[j]->record.id, (list[j]->record.title != NULL) ?