1
0
Fork 0

Improve escaping in format strings for backwards compatibility

This commit is contained in:
Duncan Ogilvie 2022-09-04 22:30:12 +02:00
parent 7a5226a182
commit 77cbbbf051
1 changed files with 33 additions and 8 deletions

View File

@ -78,6 +78,9 @@ Command::Command(const String & command)
case '{': case '{':
dataAppend(ch); dataAppend(ch);
break; break;
case '\\':
dataAppend(ch);
break;
default: default:
dataAppend('\\'); dataAppend('\\');
dataAppend(ch); dataAppend(ch);
@ -87,28 +90,50 @@ Command::Command(const String & command)
break; break;
case StringFormat: case StringFormat:
{ {
dataAppend(ch);
auto nextch = i + 1 < len ? command[i + 1] : '\0'; auto nextch = i + 1 < len ? command[i + 1] : '\0';
switch(ch) switch(ch)
{ {
case '{': case '{':
if(nextch == '{') if(nextch == '{')
{ {
dataAppend(nextch); dataAppend(ch);
i++;
}
break;
case '}':
if(nextch == '}')
{
dataAppend(nextch); dataAppend(nextch);
i++; i++;
} }
else else
{ {
dataAppend(ch);
}
break;
case '}':
if(nextch == '}')
{
dataAppend(ch);
dataAppend(nextch);
i++;
}
else
{
dataAppend(ch);
state = Text; state = Text;
} }
break; break;
case '\\':
switch(nextch)
{
case '\"':
case '\\':
dataAppend(nextch);
i++;
break;
default:
dataAppend(ch);
break;
}
break;
default:
dataAppend(ch);
break;
} }
} }
break; break;