0
0
mirror of https://github.com/vim/vim.git synced 2025-10-07 05:54:16 -04:00

patch 9.0.0113: has() is not strict about parsing the patch version

Problem:    has() is not strict about parsing the patch version.
Solution:   Check the version more strictly. (Ken Takata, closes #10752)
This commit is contained in:
K.Takata
2022-07-30 15:43:59 +01:00
committed by Bram Moolenaar
parent 0f823c3609
commit d90f91fe30
3 changed files with 29 additions and 11 deletions

View File

@@ -6458,19 +6458,26 @@ f_has(typval_T *argvars, typval_T *rettv)
x = TRUE; x = TRUE;
if (name[5] == '-' if (name[5] == '-'
&& STRLEN(name) >= 11 && STRLEN(name) >= 11
&& vim_isdigit(name[6]) && (name[6] >= '1' && name[6] <= '9'))
&& vim_isdigit(name[8])
&& vim_isdigit(name[10]))
{ {
int major = atoi((char *)name + 6); char *end;
int minor = atoi((char *)name + 8); int major, minor;
// Expect "patch-9.9.01234". // This works for patch-8.1.2, patch-9.0.3, patch-10.0.4, etc.
n = (major < VIM_VERSION_MAJOR // Not for patch-9.10.5.
|| (major == VIM_VERSION_MAJOR major = (int)strtoul((char *)name + 6, &end, 10);
&& (minor < VIM_VERSION_MINOR if (*end == '.' && vim_isdigit(end[1])
|| (minor == VIM_VERSION_MINOR && end[2] == '.' && vim_isdigit(end[3]))
&& has_patch(atoi((char *)name + 10)))))); {
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])) else if (isdigit(name[5]))
n = has_patch(atoi((char *)name + 5)); n = has_patch(atoi((char *)name + 5));

View File

@@ -35,13 +35,22 @@ func Test_version()
call assert_true(has('patch-6.9.999')) call assert_true(has('patch-6.9.999'))
call assert_true(has('patch-7.1.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'))
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'))
call assert_false(has('patch-7.4')) call assert_false(has('patch-7.4'))
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.1.0'))
call assert_false(has('patch-9.9.1')) call assert_false(has('patch-9.9.1'))
call assert_false(has('patch-abc')) 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 endfunc
func Test_op_ternary() func Test_op_ternary()

View File

@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
113,
/**/ /**/
112, 112,
/**/ /**/