From e9397c072cd099b97cbb474563cedb30aa8f77dc Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 8 Oct 2015 11:42:58 +1100 Subject: [PATCH] Autocvar: use MakeConsoleSafe --- qcsrc/common/util.qc | 10 ---------- qcsrc/lib/cvar.qh | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 12 deletions(-) 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))); } } -- 2.39.2