Skip to content

Commit 84e3175

Browse files
committed
patch 9.1.0709: GUIEnter event not found in Turkish locale
Problem: GUIEnter not found in Turkish locale (James McCoy, after v9.1.0256, the issue was there before, but v9.1.0256 made it more apparent) Solution: explicitly compare autocommand events by ASCII value and ignoring locale, because according to the documentation, events are case insensitive (:h autocommand-events) fixes: #15574 closes: #15603 Signed-off-by: Christian Brabandt <[email protected]>
1 parent bd69b39 commit 84e3175

7 files changed

Lines changed: 55 additions & 17 deletions

File tree

src/highlight.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,8 @@ highlight_set_cterm_color(
12151215

12161216
target.key = 0;
12171217
target.value = (char *)arg;
1218-
target.length = 0; // not used, see cmp_keyvalue_value_i()
1219-
entry = (keyvalue_T *)bsearch(&target, &color_name_tab, ARRAY_LENGTH(color_name_tab), sizeof(color_name_tab[0]), cmp_keyvalue_value_i);
1218+
target.length = 0; // not used, see cmp_keyvalue_value_ni()
1219+
entry = (keyvalue_T *)bsearch(&target, &color_name_tab, ARRAY_LENGTH(color_name_tab), sizeof(color_name_tab[0]), cmp_keyvalue_value_ni);
12201220
if (entry == NULL)
12211221
{
12221222
semsg(_(e_color_name_or_number_not_recognized_str), key_start);
@@ -2542,8 +2542,8 @@ gui_get_color_cmn(char_u *name)
25422542

25432543
target.key = 0;
25442544
target.value = (char *)name;
2545-
target.length = 0; // not used, see cmp_keyvalue_value_i()
2546-
entry = (keyvalue_T *)bsearch(&target, &rgb_tab, ARRAY_LENGTH(rgb_tab), sizeof(rgb_tab[0]), cmp_keyvalue_value_i);
2545+
target.length = 0; // not used, see cmp_keyvalue_value_ni()
2546+
entry = (keyvalue_T *)bsearch(&target, &rgb_tab, ARRAY_LENGTH(rgb_tab), sizeof(rgb_tab[0]), cmp_keyvalue_value_ni);
25472547
if (entry != NULL)
25482548
return gui_adjust_rgb((guicolor_T)entry->key);
25492549

src/misc2.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,24 +3090,14 @@ cmp_keyvalue_value_n(const void *a, const void *b)
30903090
return STRNCMP(kv1->value, kv2->value, MAX(kv1->length, kv2->length));
30913091
}
30923092

3093-
// compare two keyvalue_T structs by case insensitive value
3094-
int
3095-
cmp_keyvalue_value_i(const void *a, const void *b)
3096-
{
3097-
keyvalue_T *kv1 = (keyvalue_T *)a;
3098-
keyvalue_T *kv2 = (keyvalue_T *)b;
3099-
3100-
return STRICMP(kv1->value, kv2->value);
3101-
}
3102-
3103-
// compare two keyvalue_T structs by case insensitive value
3093+
// compare two keyvalue_T structs by case insensitive ASCII value
31043094
// with length
31053095
int
31063096
cmp_keyvalue_value_ni(const void *a, const void *b)
31073097
{
31083098
keyvalue_T *kv1 = (keyvalue_T *)a;
31093099
keyvalue_T *kv2 = (keyvalue_T *)b;
31103100

3111-
return STRNICMP(kv1->value, kv2->value, MAX(kv1->length, kv2->length));
3101+
return vim_strnicmp_asc(kv1->value, kv2->value, MAX(kv1->length, kv2->length));
31123102
}
31133103

src/proto/misc2.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,5 @@ int build_argv_from_list(list_T *l, char ***argv, int *argc);
6363
int get_special_pty_type(void);
6464
int cmp_keyvalue_value(const void *a, const void *b);
6565
int cmp_keyvalue_value_n(const void *a, const void *b);
66-
int cmp_keyvalue_value_i(const void *a, const void *b);
6766
int cmp_keyvalue_value_ni(const void *a, const void *b);
6867
/* vim: set ft=c : */

src/proto/strings.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void vim_strcat(char_u *to, char_u *from, size_t tosize);
1515
size_t vim_strlen_maxlen(char *s, size_t maxlen);
1616
int vim_stricmp(char *s1, char *s2);
1717
int vim_strnicmp(char *s1, char *s2, size_t len);
18+
int vim_strnicmp_asc(char *s1, char *s2, size_t len);
1819
char_u *vim_strchr(char_u *string, int c);
1920
char_u *vim_strbyte(char_u *string, int c);
2021
char_u *vim_strrchr(char_u *string, int c);

src/strings.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,33 @@ vim_strnicmp(char *s1, char *s2, size_t len)
589589
}
590590
#endif
591591

592+
/*
593+
* Compare two ASCII strings, for length "len", ignoring case, ignoring locale
594+
* (mostly matters for turkish locale where i I might be different).
595+
* return 0 for match, < 0 for smaller, > 0 for bigger
596+
*/
597+
int
598+
vim_strnicmp_asc(char *s1, char *s2, size_t len)
599+
{
600+
int i;
601+
int save_cmp_flags = cmp_flags;
602+
603+
cmp_flags |= CMP_KEEPASCII; // compare by ASCII value, ignoring locale
604+
while (len > 0)
605+
{
606+
i = vim_tolower(*s1) - vim_tolower(*s2);
607+
if (i != 0)
608+
break; // this character is different
609+
if (*s1 == NUL)
610+
break; // strings match until NUL
611+
++s1;
612+
++s2;
613+
--len;
614+
}
615+
cmp_flags = save_cmp_flags;
616+
return i;
617+
}
618+
592619
/*
593620
* Search for first occurrence of "c" in "string".
594621
* Version of strchr() that handles unsigned char strings with characters from

src/testdir/test_autocmd.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,5 +4863,24 @@ func Test_WinNewPre_crash()
48634863
let &cmdheight=_cmdheight
48644864
endfunc
48654865

4866+
" The specifics of the turkish locale may
4867+
" cause that Vim will not treat the GuiEnter autocommand
4868+
" as case insensitive and instead issues an error
4869+
func Test_GuiEnter_Turkish_locale()
4870+
try
4871+
let lng = v:lang
4872+
lang tr_TR.UTF-8
4873+
let result = execute(':au GuiEnter')
4874+
call assert_equal("\n--- Autocommands ---", result)
4875+
let result = execute(':au GUIENTER')
4876+
call assert_equal("\n--- Autocommands ---", result)
4877+
let result = execute(':au guienter')
4878+
call assert_equal("\n--- Autocommands ---", result)
4879+
exe ":lang" lng
4880+
catch /E197:/
4881+
" can't use Turkish locale
4882+
throw 'Skipped: Turkish locale not available'
4883+
endtry
4884+
endfunc
48664885

48674886
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
709,
707709
/**/
708710
708,
709711
/**/

0 commit comments

Comments
 (0)