aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-07 09:43:16 +0800
committerGitHub <noreply@github.com>2022-10-07 09:43:16 +0800
commitcfdb4cbada8c65aa57e69776bcc0f7b8b298317a (patch)
treef367b6d7d2315ab67ee6ec36384fb4f0980002d0
parentd191070913dc195309926a91f97008defd877a71 (diff)
downloadrneovim-cfdb4cbada8c65aa57e69776bcc0f7b8b298317a.tar.gz
rneovim-cfdb4cbada8c65aa57e69776bcc0f7b8b298317a.tar.bz2
rneovim-cfdb4cbada8c65aa57e69776bcc0f7b8b298317a.zip
fix: find multibyte file name in line (#20519)
And remove unnecessary unsigned casts in fold marker comparison.
-rw-r--r--src/nvim/fold.c8
-rw-r--r--src/nvim/window.c7
-rw-r--r--test/functional/core/path_spec.lua14
-rw-r--r--test/functional/fixtures/filename_with_unicode_ααα0
4 files changed, 22 insertions, 7 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 76fc531627..1872558669 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -3002,9 +3002,9 @@ static void foldlevelMarker(fline_T *flp)
// cache a few values for speed
char *startmarker = flp->wp->w_p_fmr;
- int cstart = (unsigned char)(*startmarker);
+ char cstart = *startmarker;
startmarker++;
- int cend = (unsigned char)(*foldendmarker);
+ char cend = *foldendmarker;
// Default: no start found, next level is same as current level
flp->start = 0;
@@ -3012,7 +3012,7 @@ static void foldlevelMarker(fline_T *flp)
char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
while (*s) {
- if ((unsigned char)(*s) == cstart
+ if (*s == cstart
&& STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) {
// found startmarker: set flp->lvl
s += foldstartmarkerlen;
@@ -3032,7 +3032,7 @@ static void foldlevelMarker(fline_T *flp)
flp->lvl_next++;
flp->start++;
}
- } else if ((unsigned char)(*s) == cend
+ } else if (*s == cend
&& STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) {
// found endmarker: set flp->lvl_next
s += foldendmarkerlen;
diff --git a/src/nvim/window.c b/src/nvim/window.c
index b505350892..d7ca718c68 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -6545,7 +6545,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u
// search forward for what could be the start of a file name
ptr = (char *)line + col;
- while (*ptr != NUL && !vim_isfilec(*ptr)) {
+ while (*ptr != NUL && !vim_isfilec((uint8_t)(*ptr))) {
MB_PTR_ADV(ptr);
}
if (*ptr == NUL) { // nothing found
@@ -6560,7 +6560,8 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u
while ((char_u *)ptr > line) {
if ((len = (size_t)(utf_head_off((char *)line, ptr - 1))) > 0) {
ptr -= len + 1;
- } else if (vim_isfilec(ptr[-1]) || ((options & FNAME_HYP) && path_is_url(ptr - 1))) {
+ } else if (vim_isfilec((uint8_t)ptr[-1])
+ || ((options & FNAME_HYP) && path_is_url(ptr - 1))) {
ptr--;
} else {
break;
@@ -6570,7 +6571,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u
// Search forward for the last char of the file name.
// Also allow ":/" when ':' is not in 'isfname'.
len = 0;
- while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ')
+ while (vim_isfilec((uint8_t)ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ')
|| ((options & FNAME_HYP) && path_is_url(ptr + len))
|| (is_url && vim_strchr(":?&=", ptr[len]) != NULL)) {
// After type:// we also include :, ?, & and = as valid characters, so that
diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua
index 669bc99136..61fae7622c 100644
--- a/test/functional/core/path_spec.lua
+++ b/test/functional/core/path_spec.lua
@@ -4,6 +4,8 @@ local eq = helpers.eq
local eval = helpers.eval
local command = helpers.command
local iswin = helpers.iswin
+local insert = helpers.insert
+local feed = helpers.feed
describe('path collapse', function()
local targetdir
@@ -54,3 +56,15 @@ describe('path collapse', function()
eq(expected_path, eval('expand("%:p")'))
end)
end)
+
+describe('file search', function()
+ before_each(clear)
+
+ it('find multibyte file name in line #20517', function()
+ command('cd test/functional/fixtures')
+ insert('filename_with_unicode_ααα')
+ eq('', eval('expand("%")'))
+ feed('gf')
+ eq('filename_with_unicode_ααα', eval('expand("%:t")'))
+ end)
+end)
diff --git a/test/functional/fixtures/filename_with_unicode_ααα b/test/functional/fixtures/filename_with_unicode_ααα
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/functional/fixtures/filename_with_unicode_ααα