lib/util.c: relax revision check to match existing data

This commit is contained in:
Piotr Wójcik 2019-12-14 11:43:29 +01:00 committed by Juan RP
parent be05118aa8
commit 26d853751e
2 changed files with 14 additions and 8 deletions

View File

@ -50,11 +50,12 @@
#pragma clang diagnostic ignored "-Wformat-nonliteral" #pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif #endif
static bool is_numeric(const char *str) { static bool is_revision(const char *str) {
if (str == NULL || str[0] == '\0'){ if (str == NULL || str[0] == '\0'){
return false; return false;
} }
while (isdigit(str[0])) { /* allow underscore for accepting perl-Digest-1.17_01_1 etc. */
while (isdigit(str[0]) || str[0] == '_') {
++str; ++str;
} }
return str[0] == '\0'; return str[0] == '\0';
@ -139,7 +140,7 @@ xbps_pkg_version(const char *pkg)
if (p[i] == '_') if (p[i] == '_')
break; break;
if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) {
if (!is_numeric(r + 1)) { if (!is_revision(r + 1)) {
break; break;
} }
return p; return p;
@ -236,11 +237,10 @@ xbps_pkg_revision(const char *pkg)
if (p[i] == '_') if (p[i] == '_')
break; break;
if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) {
++r; /* skip first '_' */ if (!is_revision(r + 1)) {
if (!is_numeric(r)) {
break; break;
} }
return r; return strrchr(r, '_') + 1;
} }
} }
return NULL; return NULL;
@ -264,7 +264,7 @@ xbps_pkg_name(const char *pkg)
if (p[i] == '_') if (p[i] == '_')
break; break;
if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) {
valid = is_numeric(r + 1); valid = is_revision(r + 1);
break; break;
} }
} }

View File

@ -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-v1"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v_1"), 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_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"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-7.8"), 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"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus-1"), 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_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("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("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("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("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("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("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_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"); 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");