fixed bug in HTML literal parser where escaped quotes were counted incorrectly

This commit is contained in:
Udo Schroeter 2021-11-29 11:57:21 +01:00
parent e6524f5a2a
commit d35d154edc
3 changed files with 65 additions and 49 deletions

Binary file not shown.

View File

@ -7,6 +7,7 @@ string process_html_literal(Request* context, SharedUnit* su, string content)
string HT_END = ")\");";
u8 mode = 0;
char quote_char;
bool inside_quote = false;
string code_buffer = "";
bool is_field = false;
@ -14,61 +15,72 @@ string process_html_literal(Request* context, SharedUnit* su, string content)
for(u32 i = 0; i < content.length(); i++)
{
char c = content[i];
if(mode == 1)
switch(mode)
{
if(c == '\"')
{
inside_quote = !inside_quote;
code_buffer.append(1, c);
}
else if(c == '?' && content[i+1] == '>')
{
mode = 0;
i += 1;
if(is_field)
case(0):
if(c == '<' && content[i+1] == '?')
{
pc.append(
HT_END +
"echo(html_escape( " +
code_buffer +
" )); " +
HT_START
);
code_buffer = "";
if(content[i+2] == '=')
{
is_field = true;
i += 2;
}
else
{
is_field = false;
i += 1;
}
mode = 1; // code-parsing mode
}
else
{
pc.append(HT_END + code_buffer + HT_START);
pc.append(1, c);
}
}
else
{
code_buffer.append(1, c);
}
}
else if(!inside_quote && c == '<' && content[i+1] == '?')
{
code_buffer = "";
if(content[i+2] == '=')
{
is_field = true;
i += 2;
}
else
{
is_field = false;
i += 1;
}
mode = 1;
}
/*else if(c == '\"')
{
inside_quote = !inside_quote;
pc.append(1, c);
}*/
else
{
pc.append(1, c);
break;
case(1):
if(inside_quote)
{
if(quote_char == c && content[i-1] != '\\')
inside_quote = false;
code_buffer.append(1, c);
}
else
{
if(c == '\"' || c == '\'')
{
inside_quote = true;
quote_char = c;
code_buffer.append(1, c);
}
else if(c == '?' && content[i+1] == '>')
{
mode = 0;
i += 1;
if(is_field)
{
pc.append(
HT_END +
"echo(html_escape( " +
code_buffer +
" )); " +
HT_START
);
}
else
{
pc.append(HT_END + code_buffer + HT_START);
}
}
else
{
code_buffer.append(1, c);
}
}
break;
}
}
return(HT_START + pc + HT_END);

View File

@ -75,7 +75,11 @@ bool MySQL::query(string query)
bool MySQL::query(string query, StringMap params)
{
return(query(parse_query_parameters(query, params)));
auto res = mysql_query(
(MYSQL*)connection,
parse_query_parameters(query, params).c_str()
);
return(true);
}
string MySQL::parse_query_parameters(string query, StringMap map)