diff --git a/lib/util.c b/lib/util.c index 6228d8fc..e150f27f 100644 --- a/lib/util.c +++ b/lib/util.c @@ -50,11 +50,12 @@ #pragma clang diagnostic ignored "-Wformat-nonliteral" #endif -static bool is_numeric(const char *str) { +static bool is_revision(const char *str) { if (str == NULL || str[0] == '\0'){ return false; } - while (isdigit(str[0])) { + /* allow underscore for accepting perl-Digest-1.17_01_1 etc. */ + while (isdigit(str[0]) || str[0] == '_') { ++str; } return str[0] == '\0'; @@ -139,7 +140,7 @@ xbps_pkg_version(const char *pkg) if (p[i] == '_') break; if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { - if (!is_numeric(r + 1)) { + if (!is_revision(r + 1)) { break; } return p; @@ -236,11 +237,10 @@ xbps_pkg_revision(const char *pkg) if (p[i] == '_') break; if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { - ++r; /* skip first '_' */ - if (!is_numeric(r)) { + if (!is_revision(r + 1)) { break; } - return r; + return strrchr(r, '_') + 1; } } return NULL; @@ -264,7 +264,7 @@ xbps_pkg_name(const char *pkg) if (p[i] == '_') break; if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { - valid = is_numeric(r + 1); + valid = is_revision(r + 1); break; } } diff --git a/tests/xbps/libxbps/util/main.c b/tests/xbps/libxbps/util/main.c index 41aac6ee..a619b15d 100644 --- a/tests/xbps/libxbps/util/main.c +++ b/tests/xbps/libxbps/util/main.c @@ -44,19 +44,25 @@ ATF_TC_BODY(util_test, tc) 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_name("font-adobe-100dpi-1.8_blah"), NULL); + ATF_CHECK_EQ(xbps_pkg_version("perl-PerlIO-utf8_strict"), 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); ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus-1"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), NULL); - ATF_CHECK_EQ(xbps_pkg_revision("systemd-43_1_0"), NULL); ATF_REQUIRE_STREQ(xbps_pkg_name("font-adobe-100dpi-7.8_2"), "font-adobe-100dpi"); ATF_REQUIRE_STREQ(xbps_pkg_name("systemd-43_1"), "systemd"); ATF_REQUIRE_STREQ(xbps_pkg_name("python-e_dbus-1.0_1"), "python-e_dbus"); + ATF_REQUIRE_STREQ(xbps_pkg_name("perl-Module-CoreList-5.20170715_24_1"), "perl-Module-CoreList"); + ATF_REQUIRE_STREQ(xbps_pkg_name("perl-PerlIO-utf8_strict-0.007_1"), "perl-PerlIO-utf8_strict"); ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-7.8_2"), "7.8_2"); 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_version("perl-Digest-1.17_01_1"), "1.17_01_1"); + ATF_REQUIRE_STREQ(xbps_pkg_version("perl-PerlIO-utf8_strict-0.007_1"), "0.007_1"); ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0"); + ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0"); + ATF_REQUIRE_STREQ(xbps_pkg_revision("perl-Module-CoreList-5.20170715_24_1"), "1"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>43"), "systemd"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<43"), "systemd");