]> granicus.if.org Git - vim/commitdiff
patch 9.0.0113: has() is not strict about parsing the patch version v9.0.0113
authorK.Takata <kentkt@csc.jp>
Sat, 30 Jul 2022 14:43:59 +0000 (15:43 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 30 Jul 2022 14:43:59 +0000 (15:43 +0100)
Problem:    has() is not strict about parsing the patch version.
Solution:   Check the version more strictly. (Ken Takata, closes #10752)

src/evalfunc.c
src/testdir/test_expr.vim
src/version.c

index 9b09caab733be869840ff1f51815479eee95255d..ef66aedf9a73f136593df2016e3efbac65b59dd5 100644 (file)
@@ -6458,19 +6458,26 @@ f_has(typval_T *argvars, typval_T *rettv)
            x = TRUE;
            if (name[5] == '-'
                    && STRLEN(name) >= 11
-                   && vim_isdigit(name[6])
-                   && vim_isdigit(name[8])
-                   && vim_isdigit(name[10]))
+                   && (name[6] >= '1' && name[6] <= '9'))
            {
-               int major = atoi((char *)name + 6);
-               int minor = atoi((char *)name + 8);
-
-               // Expect "patch-9.9.01234".
-               n = (major < VIM_VERSION_MAJOR
-                    || (major == VIM_VERSION_MAJOR
-                        && (minor < VIM_VERSION_MINOR
-                            || (minor == VIM_VERSION_MINOR
-                                && has_patch(atoi((char *)name + 10))))));
+               char    *end;
+               int     major, minor;
+
+               // This works for patch-8.1.2, patch-9.0.3, patch-10.0.4, etc.
+               // Not for patch-9.10.5.
+               major = (int)strtoul((char *)name + 6, &end, 10);
+               if (*end == '.' && vim_isdigit(end[1])
+                       && end[2] == '.' && vim_isdigit(end[3]))
+               {
+                   minor = atoi(end + 1);
+
+                   // Expect "patch-9.9.01234".
+                   n = (major < VIM_VERSION_MAJOR
+                        || (major == VIM_VERSION_MAJOR
+                            && (minor < VIM_VERSION_MINOR
+                                || (minor == VIM_VERSION_MINOR
+                                    && has_patch(atoi(end + 3))))));
+               }
            }
            else if (isdigit(name[5]))
                n = has_patch(atoi((char *)name + 5));
index f911cd933f1bc48b9dfcd4dab3aad773379c6c30..78d59197574c8e3fa39f56c6d011f7291ec86f42 100644 (file)
@@ -35,13 +35,22 @@ func Test_version()
   call assert_true(has('patch-6.9.999'))
   call assert_true(has('patch-7.1.999'))
   call assert_true(has('patch-7.4.123'))
+  call assert_true(has('patch-7.4.123 ')) " Traling space can be allowed.
 
   call assert_false(has('patch-7'))
   call assert_false(has('patch-7.4'))
   call assert_false(has('patch-7.4.'))
   call assert_false(has('patch-9.1.0'))
   call assert_false(has('patch-9.9.1'))
+
   call assert_false(has('patch-abc'))
+  call assert_false(has('patchabc'))
+
+  call assert_false(has('patch-8x001'))
+  call assert_false(has('patch-9X0X0'))
+  call assert_false(has('patch-9-0-0'))
+  call assert_false(has('patch-09.0.0'))
+  call assert_false(has('patch-9.00.0'))
 endfunc
 
 func Test_op_ternary()
index 4a79784b2917edb5099cdfccb22f385a9393cc28..0a6fc7253dd70dbdec21a17da2620fbead0a3dc8 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    113,
 /**/
     112,
 /**/