projects/pwm

changeset 37:e027dd4409c7

Handle empty fields correctly when filtering the list of entries
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Thu Aug 08 10:31:06 2019 +0200 (14 months ago)
parents f9501248b6bd
children 8b55f7b1c6b3
files cmd.c
line diff
     1.1 --- a/cmd.c	Wed Aug 07 11:28:07 2019 +0200
     1.2 +++ b/cmd.c	Thu Aug 08 10:31:06 2019 +0200
     1.3 @@ -426,6 +426,11 @@
     1.4  	struct pager	*pager = NULL;
     1.5  	union list_item	**list = NULL;
     1.6  	size_t		j;
     1.7 +	const char	*group;
     1.8 +	const char	*title;
     1.9 +	const char	*username;
    1.10 +	const char	*notes;
    1.11 +	const char	*url;
    1.12  	struct record	*record;
    1.13  
    1.14  	for (i = 1; i < argc; i++) {
    1.15 @@ -482,16 +487,23 @@
    1.16  			pager_printf(pager, "[%s]\n", list[j]->group.group);
    1.17  		} else {
    1.18  			record = pwfile_get_record(ctx, list[j]->record.id);
    1.19 -			if (((group_re == NULL) || (regexec(group_re,
    1.20 -			    record->group, 0, NULL, 0) == 0)) &&
    1.21 -			    ((title_re == NULL) || (regexec(title_re,
    1.22 -			    record->title, 0, NULL, 0) == 0)) &&
    1.23 -			    ((username_re == NULL) || (regexec(username_re,
    1.24 -			    record->username, 0, NULL, 0) == 0)) &&
    1.25 -			    ((notes_re == NULL) || (regexec(notes_re,
    1.26 -			    record->notes, 0, NULL, 0) == 0)) &&
    1.27 -			    ((url_re == NULL) || (regexec(url_re,
    1.28 -			    record->url, 0, NULL, 0) == 0))) {
    1.29 +			group = (record->group != NULL) ? record->group : "";
    1.30 +			title = (record->title != NULL) ? record->title : "";
    1.31 +			username = (record->username != NULL) ?
    1.32 +			    record->username : "";
    1.33 +			notes = (record->notes != NULL) ? record->notes : "";
    1.34 +			url = (record->url != NULL) ? record->url : "";
    1.35 +			if (((group_re == NULL) ||
    1.36 +			    (regexec(group_re, group, 0, NULL, 0) == 0)) &&
    1.37 +			    ((title_re == NULL) ||
    1.38 +			    (regexec(title_re, title, 0, NULL, 0) == 0)) &&
    1.39 +			    ((username_re == NULL) ||
    1.40 +			    (regexec(username_re, username, 0, NULL,
    1.41 +			    0) == 0)) &&
    1.42 +			    ((notes_re == NULL) ||
    1.43 +			    (regexec(notes_re, notes, 0, NULL, 0) == 0)) &&
    1.44 +			    ((url_re == NULL) ||
    1.45 +			    (regexec(url_re, url, 0, NULL, 0) == 0))) {
    1.46  				pager_printf(pager, "%4u %s\n",
    1.47  				    list[j]->record.id,
    1.48  				    (list[j]->record.title != NULL) ?