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

View File

@ -75,7 +75,11 @@ bool MySQL::query(string query)
bool MySQL::query(string query, StringMap params) 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) string MySQL::parse_query_parameters(string query, StringMap map)