commit 242261554e50a28c3539221d034506dfacb8f215
parent a4b2192690d7ed7c919708d8a50629c5b5cdfb50
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sun, 30 Nov 2025 10:31:43 +0800
Merge pull request #36749 from janlazo/vim-9.0.0057
vim-patch:9.0.{10,57,113}
Diffstat:
4 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
@@ -2801,19 +2801,24 @@ static void f_has(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} else if (STRNICMP(name, "patch", 5) == 0) {
if (name[5] == '-'
&& strlen(name) >= 11
- && ascii_isdigit(name[6])
- && ascii_isdigit(name[8])
- && ascii_isdigit(name[10])) {
- int major = atoi(name + 6);
- int minor = atoi(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_vim_patch(atoi(name + 10))))));
- } else {
+ && (name[6] >= '1' && name[6] <= '9')) {
+ char *end;
+
+ // This works for patch-8.1.2, patch-9.0.3, patch-10.0.4, etc.
+ // Not for patch-9.10.5.
+ int major = (int)strtoul(name + 6, &end, 10);
+ if (*end == '.' && ascii_isdigit(end[1])
+ && end[2] == '.' && ascii_isdigit(end[3])) {
+ int 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_vim_patch(atoi(end + 3))))));
+ }
+ } else if (ascii_isdigit(name[5])) {
n = has_vim_patch(atoi(name + 5));
}
} else if (STRNICMP(name, "nvim-", 5) == 0) {
diff --git a/src/nvim/version.c b/src/nvim/version.c
@@ -2543,11 +2543,14 @@ bool has_vim_patch(int n)
// Perform a binary search.
int l = 0;
int h = (int)(ARRAY_SIZE(included_patches)) - 1;
- while (l < h) {
+ while (true) {
const int m = (l + h) / 2;
if (included_patches[m] == n) {
return true;
}
+ if (l == h) {
+ break;
+ }
if (included_patches[m] < n) {
h = m;
} else {
diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim
@@ -37,12 +37,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()
diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim
@@ -44,6 +44,9 @@ func Test_has()
" Will we ever have patch 9999?
let ver = 'patch-' .. v:version / 100 .. '.' .. v:version % 100 .. '.9999'
call assert_equal(0, has(ver))
+
+ " There actually isn't a patch 9.0.0, but this is more consistent.
+ call assert_equal(1, has('patch-9.0.0'))
endfunc
func Test_empty()