fix string escaping for SVARs
* avoid double richtext conversion for mspmsg * fix minor memleak in pushident() * always escape strings for the command buffer
This commit is contained in:
+1
-1
@@ -68,7 +68,7 @@ const gibsgore [
|
||||
// "fullscreenscript" command:
|
||||
// This command allows swapping of fullscreen mode to be bound to a key.
|
||||
const fullscreenscript [ fullscreen (! $fullscreen) ]
|
||||
const editsvar [ inputcommand $$arg1 (concatword $arg1 " $" cmdbuf) (concatword "edit " $arg1 :) ]
|
||||
const editsvar [ inputcommand $$arg1 (concatword "push q (addpunct $cmdbuf) ; " $arg1 " (at $q 0) ; pop q") (concatword "edit " $arg1 :) ]
|
||||
const editmapmsg [ editsvar mapmsg ]
|
||||
const return [ result $arg1 ]
|
||||
const run [ exec (concatword config/ $arg1 .cfg) ]
|
||||
|
||||
@@ -39,7 +39,7 @@ void clearstack(ident &id)
|
||||
|
||||
void pushident(ident &id, char *val, int context = execcontext)
|
||||
{
|
||||
if(id.type != ID_ALIAS) return;
|
||||
if(id.type != ID_ALIAS) { delete[] val; return; }
|
||||
identstack *stack = new identstack;
|
||||
stack->action = id.executing==id.action ? newstring(id.action) : id.action;
|
||||
stack->context = id.context;
|
||||
@@ -1426,16 +1426,17 @@ COMMANDF(rnd, "i", (int *a) { intret(*a>0 ? rnd(*a) : 0); });
|
||||
|
||||
#ifndef STANDALONE
|
||||
|
||||
const char *escapestring(const char *s, bool force)
|
||||
const char *escapestring(const char *s, bool force, bool noquotes)
|
||||
{
|
||||
static vector<char> strbuf[3];
|
||||
static int stridx = 0;
|
||||
if(noquotes) force = false;
|
||||
if(!s) return force ? "\"\"" : "";
|
||||
if(!force && !*(s + strcspn(s, "\"/\\;()[] \f\t\r\n"))) return s;
|
||||
stridx = (stridx + 1) % 3;
|
||||
vector<char> &buf = strbuf[stridx];
|
||||
buf.setsize(0);
|
||||
buf.add('"');
|
||||
if(!noquotes) buf.add('"');
|
||||
for(; *s; s++) switch(*s)
|
||||
{
|
||||
case '\n': buf.put("\\n", 2); break;
|
||||
@@ -1445,7 +1446,8 @@ const char *escapestring(const char *s, bool force)
|
||||
case '\\': buf.put("\\\\", 2); break;
|
||||
default: buf.add(*s); break;
|
||||
}
|
||||
buf.put("\"\0", 2);
|
||||
if(!noquotes) buf.add('"');
|
||||
buf.add(0);
|
||||
return buf.getbuf();
|
||||
}
|
||||
COMMANDF(escape, "s", (const char *s) { result(escapestring(s));});
|
||||
|
||||
@@ -300,7 +300,7 @@ void saycommand(char *init) // turns input to the comman
|
||||
setscope(false);
|
||||
setburst(false);
|
||||
if(!editmode) keyrepeat(saycommandon);
|
||||
copystring(cmdline.buf, init ? init : "");
|
||||
copystring(cmdline.buf, init ? escapestring(init, false, true) : "");
|
||||
DELETEA(cmdaction);
|
||||
DELETEA(cmdprompt);
|
||||
cmdline.pos = -1;
|
||||
@@ -322,8 +322,7 @@ SVARFF(mapmsg,
|
||||
},
|
||||
{ // set new mapmsg
|
||||
string text;
|
||||
filterrichtext(text, mapmsg);
|
||||
filtertext(text, text, FTXT__MAPMSG);
|
||||
filtertext(text, mapmsg, FTXT__MAPMSG);
|
||||
copystring(hdr.maptitle, text, 128);
|
||||
if(editmode) unsavededits++;
|
||||
});
|
||||
|
||||
+1
-1
@@ -847,7 +847,7 @@ extern char *strreplace(char *dest, const char *source, const char *search, cons
|
||||
extern void pushscontext(int newcontext);
|
||||
extern int popscontext();
|
||||
extern int curscontext();
|
||||
extern const char *escapestring(const char *s, bool force = true);
|
||||
extern const char *escapestring(const char *s, bool force = true, bool noquotes = false);
|
||||
extern int execcontext;
|
||||
extern const char *currentserver(int i);
|
||||
extern void setcontext(const char *context, const char *info);
|
||||
|
||||
Reference in New Issue
Block a user