summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-11-05 20:25:52 +0100
committerBram Moolenaar <Bram@vim.org>2018-11-05 20:25:52 +0100
commit389ab7122bec99c11ad4ce6d87cc6f38a21e4e40 (patch)
treefe54e4766e9d306d80713345412a9bb5bd68d699 /src/ex_cmds2.c
parent9e353b5265bd7fa103caf4e5a9b3c99f344f548e (diff)
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8v8.1.0512
Problem: 'helplang' default is inconsistent for C and C.UTF-8. Solution: Don't accept a value unless it starts with two letters.
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r--src/ex_cmds2.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 9a23f82055..3a4bce8a26 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -5359,6 +5359,16 @@ gettext_lang(char_u *name)
#if defined(FEAT_MULTI_LANG) || defined(PROTO)
/*
+ * Return TRUE when "lang" starts with a valid language name.
+ * Rejects NULL, empty string, "C", "C.UTF-8" and others.
+ */
+ static int
+is_valid_mess_lang(char_u *lang)
+{
+ return lang != NULL && ASCII_ISALPHA(lang[0]) && ASCII_ISALPHA(lang[1]);
+}
+
+/*
* Obtain the current messages language. Used to set the default for
* 'helplang'. May return NULL or an empty string.
*/
@@ -5379,17 +5389,17 @@ get_mess_lang(void)
# endif
# else
p = mch_getenv((char_u *)"LC_ALL");
- if (p == NULL || *p == NUL)
+ if (!is_valid_mess_lang(p))
{
p = mch_getenv((char_u *)"LC_MESSAGES");
- if (p == NULL || *p == NUL)
+ if (!is_valid_mess_lang(p))
p = mch_getenv((char_u *)"LANG");
}
# endif
# ifdef WIN32
p = gettext_lang(p);
# endif
- return p;
+ return is_valid_mess_lang(p) ? p : NULL;
}
#endif