From 4c963d719c4892e82c997e63bd21ac88f23dcb17 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 23 Feb 2018 14:52:05 +0100 Subject: [PATCH] libnm/utils: drop part after a dash in product name It's always garbage. At this point we seem to reasonably handle all product names that come from hwdb. --- libnm/nm-libnm-utils.c | 9 +++++++++ libnm/tests/test-general.c | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c index 4a4922b6ed..3621906597 100644 --- a/libnm/nm-libnm-utils.c +++ b/libnm/nm-libnm-utils.c @@ -543,11 +543,20 @@ nm_utils_fixup_product_string (const char *desc) NULL, }; char *desc_full; + char *p; desc_full = _fixup_string (desc, IGNORED_PHRASES, IGNORED_WORDS, FALSE); if (!desc_full) return NULL; + /* Chop off everything after a '-'. */ + for (p = desc_full; *p; p++) { + if (p[0] == ' ' && p[1] == '-' && p[2] == ' ') { + p[0] = '\0'; + break; + } + } + nm_assert (g_utf8_validate (desc_full, -1, NULL)); return desc_full; diff --git a/libnm/tests/test-general.c b/libnm/tests/test-general.c index 6ae0e97c93..a6968c17ec 100644 --- a/libnm/tests/test-general.c +++ b/libnm/tests/test-general.c @@ -474,9 +474,17 @@ test_fixup_product_string (void) T (nm_utils_fixup_product_string, "82559 Ethernet Controller", "82559"); T (nm_utils_fixup_product_string, "82559 InBusiness 10/100", "82559 InBusiness"); T (nm_utils_fixup_product_string, "8255xER/82551IT Fast Ethernet Controller", "8255xER/82551IT"); + T (nm_utils_fixup_product_string, "82562 EM/EX/GX - PRO/100 VM Ethernet Controller", "82562 EM/EX/GX"); + T (nm_utils_fixup_product_string, "82562 EM/EX/GX - PRO/100 VM (LOM) Ethernet Controller", "82562 EM/EX/GX"); + T (nm_utils_fixup_product_string, "82562EM/EX/GX - PRO/100 VM (LOM) Ethernet Controller Mobile", "82562EM/EX/GX"); + T (nm_utils_fixup_product_string, "82562ET/EZ/GT/GZ - PRO/100 VE Ethernet Controller", "82562ET/EZ/GT/GZ"); + T (nm_utils_fixup_product_string, "82562ET/EZ/GT/GZ - PRO/100 VE (LOM) Ethernet Controller", "82562ET/EZ/GT/GZ"); + T (nm_utils_fixup_product_string, "82562ET/EZ/GT/GZ - PRO/100 VE (LOM) Ethernet Controller Mobile", "82562ET/EZ/GT/GZ"); T (nm_utils_fixup_product_string, "82562EZ 10/100 Ethernet Controller", "82562EZ"); T (nm_utils_fixup_product_string, "82562G 10/100 Network Connection", "82562G"); T (nm_utils_fixup_product_string, "82562G-2 10/100 Network Connection", "82562G-2"); + T (nm_utils_fixup_product_string, "82562G - PRO/100 VE Ethernet Controller Mobile", "82562G"); + T (nm_utils_fixup_product_string, "82562G - PRO/100 VE (LOM) Ethernet Controller", "82562G"); T (nm_utils_fixup_product_string, "82562GT 10/100 Network Connection", "82562GT"); T (nm_utils_fixup_product_string, "82562GT-2 10/100 Network Connection", "82562GT-2"); T (nm_utils_fixup_product_string, "82562V 10/100 Network Connection", "82562V");