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.
This commit is contained in:
Lubomir Rintel 2018-02-23 14:52:05 +01:00
parent 0c151ae39d
commit 4c963d719c
2 changed files with 17 additions and 0 deletions

View file

@ -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;

View file

@ -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");