commit: 712cbd379172e444c399a48d08d76a402e822697 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Thu Apr 12 18:28:20 2018 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Thu Apr 12 18:28:20 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=712cbd37
atom_explode: try harder to find correct PV It's not enough to find a hyphen followed by something that looks like a version, it needs to be verified it really is, else it is part of the package name. Bug: https://bugs.gentoo.org/653032 libq/atom_explode.c | 51 ++++++++++++++++++++++++--------------------------- tests/qatom/dotest | 3 +++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libq/atom_explode.c b/libq/atom_explode.c index ec0fc5a..07d9cec 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -189,13 +189,31 @@ atom_explode(const char *atom) * SLOT, REPO or '*' * PN must not end in a hyphen followed by anything matching version * syntax, version syntax starts with a number, so "-[0-9]" is a - * separator from PN to PV* */ + * separator from PN to PV* -- except it doesn't when the thing + * doesn't validate as version :( */ ptr = ret->PN; while ((ptr = strchr(ptr, '-')) != NULL) { + char *pv; ptr++; - if (*ptr >= '0' && *ptr <= '9') - break; + if (!isdigit(*ptr)) + continue; + + /* so we should have something like "-2" here, see if this + * checks out as valid version string */ + pv = ptr; + while (*++ptr != '\0') { + if (*ptr != '.' && !isdigit(*ptr)) + break; + } + /* allow for 1 optional suffix letter */ + if (*ptr >= 'a' && *ptr <= 'z') + ret->letter = *ptr++; + if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { + ptr = pv; + break; /* valid */ + } + ret->letter = '\0'; } if (ptr == NULL) { @@ -216,7 +234,7 @@ atom_explode(const char *atom) } break; } - --ptr; + ptr--; } strcpy(ret->P, ret->PN); ret->PV[-1] = '\0'; @@ -256,29 +274,8 @@ atom_explode(const char *atom) ret->suffixes[idx] = t; } - /* skip back to the "end" */ - for (ptr = ret->PV; *ptr != '\0' && *ptr != '_'; ptr++) - ; - ptr--; - - /* allow for 1 optional suffix letter */ - if (*ptr >= 'a' && *ptr <= 'z') - ret->letter = *ptr--; - - /* eat the trailing version number [.0-9]+ */ - while (ptr > ret->PV) { - if (*ptr != '.' && !isdigit(*ptr)) - break; - ptr--; - } - - if (ptr != ret->PV) { - /* PV isn't exactly a number */ - ret->PV = ret->PVR = NULL; - } else { - ptr = stpcpy(ret->PVR, ret->PV); - sprintf(ptr, "-r%i", ret->PR_int); - } + ptr = stpcpy(ret->PVR, ret->PV); + sprintf(ptr, "-r%i", ret->PR_int); return ret; } diff --git a/tests/qatom/dotest b/tests/qatom/dotest index a0e6a34..01900e6 100755 --- a/tests/qatom/dotest +++ b/tests/qatom/dotest @@ -48,5 +48,8 @@ test f14 "foo-r1" -F '%{PN}' "foo-r1" # bug #526596 test f15 "app-emacs diff-mode-" \ -F '%{CATEGORY} %{PN}' \ "app-emacs/diff-mode-" +test f16 "media-fonts font-adobe-100dpi 1.0.3 r1" \ + -F '%{CATEGORY} %{PN} %{PV} %{PR}' \ + "media-fonts/font-adobe-100dpi-1.0.3-r1" end
