Bugfix: escaped % in format did not work

This commit is contained in:
zimoch
2011-02-24 16:12:43 +00:00
parent 2dc0918926
commit 7f1f1c1e65

View File

@ -1073,7 +1073,7 @@ compileString(StreamBuffer& buffer, const char*& source,
// 1) read a line from protocol source and code quoted strings, // 1) read a line from protocol source and code quoted strings,
// numerical bytes, tokens, etc, and replace variables and parameters // numerical bytes, tokens, etc, and replace variables and parameters
// 2) replace the formats in the line // 2) replace the formats in the line
// thus variables can be replaces inside the format info string // thus variables can be replaced inside the format info string
while (1) while (1)
{ {
@ -1088,33 +1088,39 @@ compileString(StreamBuffer& buffer, const char*& source,
if (formatType != NoFormat) if (formatType != NoFormat)
{ {
int nformats=0; int nformats=0;
debug("StreamProtocolParser::Protocol::compileString " char c;
"looking for formats at pos %d in \"%s\"\n", formatpos, buffer.expand(formatpos)()); while ((c = buffer[formatpos]) != '\0')
while ((formatpos = buffer.find('%', formatpos)) != -1)
{ {
if (buffer[formatpos-1] == esc) continue; if (c == esc) {
debug("StreamProtocolParser::Protocol::compileString " // ignore escaped %
"format=\"%s\"\n", buffer.expand(formatpos)()); formatpos+=2;
nformats++; continue;
formatbuffer.clear();
const char* p = buffer(formatpos);
if (!compileFormat(formatbuffer, p, formatType, client))
{
p = buffer(formatpos);
formatbuffer.clear();
printString(formatbuffer, p);
error(line, filename(),
"in format string: \"%s\"\n",
formatbuffer());
return false;
} }
int formatlen = p - buffer(formatpos); if (c == '%') {
buffer.replace(formatpos, formatlen, formatbuffer); debug("StreamProtocolParser::Protocol::compileString "
debug("StreamProtocolParser::Protocol::compileString " "format=\"%s\"\n", buffer.expand(formatpos)());
"replaced by: \"%s\"\n", buffer.expand(formatpos)()); nformats++;
formatpos += formatbuffer.length(); formatbuffer.clear();
const char* p = buffer(formatpos);
if (!compileFormat(formatbuffer, p, formatType, client))
{
p = buffer(formatpos);
formatbuffer.clear();
printString(formatbuffer, p);
error(line, filename(),
"in format string: \"%s\"\n",
formatbuffer());
return false;
}
int formatlen = p - buffer(formatpos);
buffer.replace(formatpos, formatlen, formatbuffer);
debug("StreamProtocolParser::Protocol::compileString "
"replaced by: \"%s\"\n", buffer.expand(formatpos)());
formatpos += formatbuffer.length();
continue;
}
formatpos ++;
} }
formatpos = buffer.length();
debug("StreamProtocolParser::Protocol::compileString " debug("StreamProtocolParser::Protocol::compileString "
"%d formats found in line %d\n", nformats, line); "%d formats found in line %d\n", nformats, line);
} }