diff --git a/lib/util.c b/lib/util.c index c2593c39..dcea8a99 100644 --- a/lib/util.c +++ b/lib/util.c @@ -93,14 +93,20 @@ const char * xbps_pkg_version(const char *pkg) { const char *p; + bool valid = false; if ((p = strrchr(pkg, '-')) == NULL) return NULL; - if (!isdigit((unsigned char)p[1])) - return NULL; - - if (strchr(p, '_') == NULL) + for (unsigned int i = 0; i < strlen(p); i++) { + if (p[i] == '_') + break; + if (isdigit((unsigned char)p[i]) && strchr(p, '_')) { + valid = true; + break; + } + } + if (!valid) return NULL; return p + 1; /* skip first '_' */ @@ -129,14 +135,20 @@ xbps_pkg_name(const char *pkg) const char *p; char *buf; unsigned int len; + bool valid = false; if ((p = strrchr(pkg, '-')) == NULL) return NULL; - if (!isdigit((unsigned char)p[1])) - return NULL; - - if (strchr(p, '_') == NULL) + for (unsigned int i = 0; i < strlen(p); i++) { + if (p[i] == '_') + break; + if (isdigit((unsigned char)p[i]) && strchr(p, '_')) { + valid = true; + break; + } + } + if (!valid) return NULL; len = strlen(pkg) - strlen(p) + 1; diff --git a/tests/xbps/libxbps/util/main.c b/tests/xbps/libxbps/util/main.c index cc1cb655..5a720ebd 100644 --- a/tests/xbps/libxbps/util/main.c +++ b/tests/xbps/libxbps/util/main.c @@ -41,6 +41,8 @@ ATF_TC_BODY(util_test, tc) ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi"), NULL); ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-7.8"), NULL); ATF_CHECK_EQ(xbps_pkg_name("python-e_dbus"), NULL); + ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v1"), NULL); + ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v_1"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-7.8"), NULL); ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus"), NULL); @@ -52,6 +54,7 @@ ATF_TC_BODY(util_test, tc) ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-7.8_2"), "7.8_2"); ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), "1.8_blah"); ATF_REQUIRE_STREQ(xbps_pkg_version("python-e_dbus-1_1"), "1_1"); + ATF_REQUIRE_STREQ(xbps_pkg_version("fs-utils-v1_1"), "v1_1"); ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0"); ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");