commit:     a7d916ac978023fe35dcd8666d7bc913bab3b0a9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri May 18 16:55:58 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri May 18 16:55:58 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a7d916ac

atom_explode: find the last version-like component

We need to keep on searching until we reached the end of the
package/version string, since package names may contain things which are
valid versions, as long as they don't end with them.

Bug: https://bugs.gentoo.org/567336

 libq/atom_explode.c | 41 +++++++++++++++++++++++------------------
 tests/qatom/dotest  |  3 +++
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index 07d9cec..a4ba569 100644
--- a/libq/atom_explode.c
+++ b/libq/atom_explode.c
@@ -193,27 +193,32 @@ atom_explode(const char *atom)
         * doesn't validate as version :( */
 
        ptr = ret->PN;
-       while ((ptr = strchr(ptr, '-')) != NULL) {
+       {
+               char *lastpv = NULL;
                char *pv;
-               ptr++;
-               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 */
+               while ((ptr = strchr(ptr, '-')) != NULL) {
+                       ptr++;
+                       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 == '-') {
+                               lastpv = pv;
+                               continue;  /* valid, keep searching */
+                       }
+                       ret->letter = '\0';
                }
-               ret->letter = '\0';
+               ptr = lastpv;
        }
 
        if (ptr == NULL) {

diff --git a/tests/qatom/dotest b/tests/qatom/dotest
index 01900e6..c879624 100755
--- a/tests/qatom/dotest
+++ b/tests/qatom/dotest
@@ -51,5 +51,8 @@ test f15 "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"
+test f17 "games-rpg eschalon-book-1-demo 106 r1" \
+                      -F '%{CATEGORY} %{PN} %{PV} %{PR}' \
+                                       "games-rpg/eschalon-book-1-demo-106-r1"
 
 end

Reply via email to