fix: find multibyte file name in line (#20519)

And remove unnecessary unsigned casts in fold marker comparison.
This commit is contained in:
zeertzjq
2022-10-07 09:43:16 +08:00
committed by GitHub
parent d191070913
commit cfdb4cbada
4 changed files with 22 additions and 7 deletions

View File

@ -3002,9 +3002,9 @@ static void foldlevelMarker(fline_T *flp)
// cache a few values for speed // cache a few values for speed
char *startmarker = flp->wp->w_p_fmr; char *startmarker = flp->wp->w_p_fmr;
int cstart = (unsigned char)(*startmarker); char cstart = *startmarker;
startmarker++; startmarker++;
int cend = (unsigned char)(*foldendmarker); char cend = *foldendmarker;
// Default: no start found, next level is same as current level // Default: no start found, next level is same as current level
flp->start = 0; 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); char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
while (*s) { while (*s) {
if ((unsigned char)(*s) == cstart if (*s == cstart
&& STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) {
// found startmarker: set flp->lvl // found startmarker: set flp->lvl
s += foldstartmarkerlen; s += foldstartmarkerlen;
@ -3032,7 +3032,7 @@ static void foldlevelMarker(fline_T *flp)
flp->lvl_next++; flp->lvl_next++;
flp->start++; flp->start++;
} }
} else if ((unsigned char)(*s) == cend } else if (*s == cend
&& STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) { && STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) {
// found endmarker: set flp->lvl_next // found endmarker: set flp->lvl_next
s += foldendmarkerlen; s += foldendmarkerlen;

View File

@ -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 // search forward for what could be the start of a file name
ptr = (char *)line + col; ptr = (char *)line + col;
while (*ptr != NUL && !vim_isfilec(*ptr)) { while (*ptr != NUL && !vim_isfilec((uint8_t)(*ptr))) {
MB_PTR_ADV(ptr); MB_PTR_ADV(ptr);
} }
if (*ptr == NUL) { // nothing found 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) { while ((char_u *)ptr > line) {
if ((len = (size_t)(utf_head_off((char *)line, ptr - 1))) > 0) { if ((len = (size_t)(utf_head_off((char *)line, ptr - 1))) > 0) {
ptr -= len + 1; 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--; ptr--;
} else { } else {
break; 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. // Search forward for the last char of the file name.
// Also allow ":/" when ':' is not in 'isfname'. // Also allow ":/" when ':' is not in 'isfname'.
len = 0; 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)) || ((options & FNAME_HYP) && path_is_url(ptr + len))
|| (is_url && vim_strchr(":?&=", ptr[len]) != NULL)) { || (is_url && vim_strchr(":?&=", ptr[len]) != NULL)) {
// After type:// we also include :, ?, & and = as valid characters, so that // After type:// we also include :, ?, & and = as valid characters, so that

View File

@ -4,6 +4,8 @@ local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local iswin = helpers.iswin local iswin = helpers.iswin
local insert = helpers.insert
local feed = helpers.feed
describe('path collapse', function() describe('path collapse', function()
local targetdir local targetdir
@ -54,3 +56,15 @@ describe('path collapse', function()
eq(expected_path, eval('expand("%:p")')) eq(expected_path, eval('expand("%:p")'))
end) end)
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)