From: Adam Dickmeiss Date: Fri, 5 Jul 2013 12:36:04 +0000 (+0200) Subject: Deal with " inside embedded JS X-Git-Tag: v1.3.59~14 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=a58c13aa3753e1d549ad643d3d7268a8ca431714;p=metaproxy-moved-to-github.git Deal with " inside embedded JS --- diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 80a876a..5fa1e63 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -425,7 +425,8 @@ void yf::HttpRewrite::Event::text(const char *value, int len) static bool embed_quoted_literal( std::string &content, std::map &vars, - mp::filter::HttpRewrite::RulePtr ruleptr) + mp::filter::HttpRewrite::RulePtr ruleptr, + bool html_context) { bool replace = false; std::string res; @@ -433,7 +434,28 @@ static bool embed_quoted_literal( const char *cp0 = cp; while (*cp) { - if (*cp == '"' || *cp == '\'') + if (html_context && !strncmp(cp, """, 6)) + { + cp += 6; + res.append(cp0, cp - cp0); + cp0 = cp; + while (*cp) + { + if (!strncmp(cp, """, 6)) + break; + if (*cp == '\n') + break; + cp++; + } + if (!*cp) + break; + std::string s(cp0, cp - cp0); + if (ruleptr->test_patterns(vars, s, true)) + replace = true; + cp0 = cp; + res.append(s); + } + else if (*cp == '"' || *cp == '\'') { int m = *cp; cp++; @@ -473,7 +495,7 @@ bool yf::HttpRewrite::Within::exec( { if (type == "quoted-literal") { - return embed_quoted_literal(txt, vars, rule); + return embed_quoted_literal(txt, vars, rule, true); } else { @@ -685,7 +707,7 @@ void yf::HttpRewrite::Content::quoted_literal( { std::list::const_iterator it = within_list.begin(); if (it != within_list.end()) - embed_quoted_literal(content, vars, it->rule); + embed_quoted_literal(content, vars, it->rule, false); } void yf::HttpRewrite::Content::configure( diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index f26feae..9ac02c0 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -83,6 +83,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) " \n" " \n" " \n" + " \n" " \n" " \n" " \n" @@ -138,12 +139,12 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) " Another abs link" "" "" - "" + "" ""; const char *resp_expected = "HTTP/1.1 200 OK\r\n" - "Content-Length: 573\r\n" + "Content-Length: 605\r\n" "Content-Type: text/html\r\n" "Link: ; rel=absolute\r\n" "Link: ; rel=relative\r\n" @@ -167,7 +168,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) " Another abs link" "" "" - "" + "" ""; Z_GDU *gdu_res;