From: TimePath Date: Thu, 8 Oct 2015 00:42:58 +0000 (+1100) Subject: Autocvar: use MakeConsoleSafe X-Git-Tag: xonotic-v0.8.2~1853 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e9397c072cd099b97cbb474563cedb30aa8f77dc;p=xonotic%2Fxonotic-data.pk3dir.git Autocvar: use MakeConsoleSafe --- diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 4b6a346ff..e93fd6a39 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2215,16 +2215,6 @@ string strlimitedlen(string input, string truncation, float strip_colors, float return strcat(substring(input, 0, (strlen(input) - strlen(truncation))), truncation); }*/ -// escape the string to make it safe for consoles -string MakeConsoleSafe(string input) -{ - input = strreplace("\n", "", input); - input = strreplace("\\", "\\\\", input); - input = strreplace("$", "$$", input); - input = strreplace("\"", "\\\"", input); - return input; -} - #ifdef CSQC entity ReadCSQCEntity() { diff --git a/qcsrc/lib/cvar.qh b/qcsrc/lib/cvar.qh index a02ec0f00..e30de507b 100644 --- a/qcsrc/lib/cvar.qh +++ b/qcsrc/lib/cvar.qh @@ -6,6 +6,16 @@ void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f) { } +/** escape the string to make it safe for consoles */ +string MakeConsoleSafe(string input) +{ + input = strreplace("\n", "", input); + input = strreplace("\\", "\\\\", input); + input = strreplace("$", "$$", input); + input = strreplace("\"", "\\\"", input); + return input; +} + void RegisterCvars_Set(string name, string def, string desc, bool archive, string file) { string val = string_null; @@ -14,9 +24,9 @@ void RegisterCvars_Set(string name, string def, string desc, bool archive, strin // Need to unset first to change the default localcmd(sprintf("\nunset %s\n", name)); } - localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, def, desc)); + localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, MakeConsoleSafe(def), MakeConsoleSafe(desc))); if (val) { - localcmd(sprintf("\n%s \"%s\"\n", name, val)); + localcmd(sprintf("\n%s \"%s\"\n", name, MakeConsoleSafe(val))); } }