From 42141acc64f4e3be596a6a4a239aba4a78420588 Mon Sep 17 00:00:00 2001
From: Timo Teräs <timo.teras@iki.fi>
Date: Mon, 6 Mar 2023 21:37:29 +0200
Subject: db: case insensitive searches

fixes #10871
---
 src/apk_database.h | 2 +-
 src/app_search.c   | 4 ++--
 src/database.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/apk_database.h b/src/apk_database.h
index 42f465d..0539ab8 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -192,7 +192,7 @@ typedef union apk_database_or_void {
 } apk_database_t __attribute__ ((__transparent_union__));
 
 static inline int apk_name_cmp_display(const struct apk_name *a, const struct apk_name *b) {
-	return strcmp(a->name, b->name);
+	return strcasecmp(a->name, b->name) ?: strcmp(a->name, b->name);
 }
 struct apk_provider_array *apk_name_sorted_providers(struct apk_name *);
 
diff --git a/src/app_search.c b/src/app_search.c
index 1dcb7b6..ab51d6d 100644
--- a/src/app_search.c
+++ b/src/app_search.c
@@ -118,8 +118,8 @@ static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg)
 
 	if (ctx->search_description) {
 		foreach_array_item(pmatch, ctx->filter) {
-			if (fnmatch(*pmatch, pkg->description, 0) == 0 ||
-			    fnmatch(*pmatch, pkg->name->name, 0) == 0)
+			if (fnmatch(*pmatch, pkg->description, FNM_CASEFOLD) == 0 ||
+			    fnmatch(*pmatch, pkg->name->name, FNM_CASEFOLD) == 0)
 				goto match;
 		}
 		return;
diff --git a/src/database.c b/src/database.c
index e8865b1..bc25683 100644
--- a/src/database.c
+++ b/src/database.c
@@ -3123,7 +3123,7 @@ static int apk_string_match(const char *str, struct apk_string_array *filter, co
 	char **pmatch;
 
 	foreach_array_item(pmatch, filter) {
-		if (fnmatch(*pmatch, str, 0) == 0) {
+		if (fnmatch(*pmatch, str, FNM_CASEFOLD) == 0) {
 			*res = *pmatch;
 			return 1;
 		}
-- 
cgit v1.2.3-70-g09d2