util.c: add stricter checks for pkgver conformance (v2).
There was another case where it now was failing: "fs-utils-v1.00_1". Previous code didn't take into account that a valid version might also contain a non digit after '-'. Added more tests to the testsuite to verify its correctness.
This commit is contained in:
parent
c44d7070a4
commit
c9825feb29
28
lib/util.c
28
lib/util.c
@ -93,14 +93,20 @@ const char *
|
|||||||
xbps_pkg_version(const char *pkg)
|
xbps_pkg_version(const char *pkg)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
if ((p = strrchr(pkg, '-')) == NULL)
|
if ((p = strrchr(pkg, '-')) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!isdigit((unsigned char)p[1]))
|
for (unsigned int i = 0; i < strlen(p); i++) {
|
||||||
return NULL;
|
if (p[i] == '_')
|
||||||
|
break;
|
||||||
if (strchr(p, '_') == NULL)
|
if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return p + 1; /* skip first '_' */
|
return p + 1; /* skip first '_' */
|
||||||
@ -129,14 +135,20 @@ xbps_pkg_name(const char *pkg)
|
|||||||
const char *p;
|
const char *p;
|
||||||
char *buf;
|
char *buf;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
if ((p = strrchr(pkg, '-')) == NULL)
|
if ((p = strrchr(pkg, '-')) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!isdigit((unsigned char)p[1]))
|
for (unsigned int i = 0; i < strlen(p); i++) {
|
||||||
return NULL;
|
if (p[i] == '_')
|
||||||
|
break;
|
||||||
if (strchr(p, '_') == NULL)
|
if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
len = strlen(pkg) - strlen(p) + 1;
|
len = strlen(pkg) - strlen(p) + 1;
|
||||||
|
@ -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"), NULL);
|
||||||
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-7.8"), 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("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"), 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);
|
||||||
@ -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-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("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("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-43_1_0"), "0");
|
||||||
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_pkgpattern_name("systemd>=43"), "systemd");
|
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");
|
||||||
|
Loading…
Reference in New Issue
Block a user