From: Adam Dickmeiss Date: Thu, 27 Jun 2013 12:33:01 +0000 (+0200) Subject: HTMLParserEvent, attributes takes quoting sep X-Git-Tag: v1.3.59~35 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=288111986392ffbd733d71cd964f49437b899bdb;p=metaproxy-moved-to-github.git HTMLParserEvent, attributes takes quoting sep as argument, so that quoting (if any) is preserved. --- diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 293886a..5a4ca83 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -85,7 +85,8 @@ namespace metaproxy_1 { void anyTagEnd(const char *tag, int tag_len, int close_it); void attribute(const char *tag, int tag_len, const char *attr, int attr_len, - const char *value, int val_len); + const char *value, int val_len, + const char *sep); void closeTag(const char *tag, int tag_len); void text(const char *value, int len); const Phase *m_phase; @@ -304,7 +305,8 @@ void yf::HttpRewrite::Event::anyTagEnd(const char *tag, int tag_len, void yf::HttpRewrite::Event::attribute(const char *tag, int tag_len, const char *attr, int attr_len, - const char *value, int val_len) + const char *value, int val_len, + const char *sep) { std::list::const_iterator it = m_phase->within_list.begin(); bool subst = false; @@ -332,7 +334,8 @@ void yf::HttpRewrite::Event::attribute(const char *tag, int tag_len, wrbuf_putc(m_w, ' '); wrbuf_write(m_w, attr, attr_len); - wrbuf_puts(m_w, "=\""); + wrbuf_puts(m_w, "="); + wrbuf_puts(m_w, sep); std::string output; if (subst) @@ -344,7 +347,7 @@ void yf::HttpRewrite::Event::attribute(const char *tag, int tag_len, wrbuf_write(m_w, value, val_len); else wrbuf_puts(m_w, output.c_str()); - wrbuf_puts(m_w, "\""); + wrbuf_puts(m_w, sep); } void yf::HttpRewrite::Event::closeTag(const char *tag, int tag_len) diff --git a/src/html_parser.cpp b/src/html_parser.cpp index 1436553..ddbbbe0 100644 --- a/src/html_parser.cpp +++ b/src/html_parser.cpp @@ -44,7 +44,7 @@ namespace metaproxy_1 { const char *cp); int skipAttribute(HTMLParserEvent &event, const char *cp, int *attr_len, - const char **value, int *val_len); + const char **value, int *val_len, int *tr); Rep(); ~Rep(); int m_verbose; @@ -99,7 +99,8 @@ static int skipName(const char *cp) int mp::HTMLParser::Rep::skipAttribute(HTMLParserEvent &event, const char *cp, int *attr_len, - const char **value, int *val_len) + const char **value, int *val_len, + int *tr) { int i = skipName(cp); *attr_len = i; @@ -114,9 +115,9 @@ int mp::HTMLParser::Rep::skipAttribute(HTMLParserEvent &event, i += skipSpace(cp + i); if (cp[i] == '\"' || cp[i] == '\'') { - char tr = cp[i]; + *tr = cp[i]; v0 = ++i; - while (cp[i] != tr && cp[i]) + while (cp[i] != *tr && cp[i]) i++; v1 = i; if (cp[i]) @@ -124,6 +125,7 @@ int mp::HTMLParser::Rep::skipAttribute(HTMLParserEvent &event, } else { + *tr = 0; v0 = i; while (cp[i] && !strchr(SPACECHR ">", cp[i])) i++; @@ -147,14 +149,18 @@ int mp::HTMLParser::Rep::tagAttrs(HTMLParserEvent &event, int attr_len; const char *value; int val_len; - int nor = skipAttribute(event, cp+i, &attr_len, &value, &val_len); + int tr; + int nor = skipAttribute(event, cp+i, &attr_len, &value, &val_len, &tr); i += nor; if (nor) { + char x[2]; + x[0] = tr; + x[1] = 0; if (m_verbose) printf ("------ attr %.*s=%.*s\n", attr_len, attr_name, val_len, value); - event.attribute(name, len, attr_name, attr_len, value, val_len); + event.attribute(name, len, attr_name, attr_len, value, val_len, x); } else { diff --git a/src/html_parser.hpp b/src/html_parser.hpp index 8eeb152..3e10daf 100644 --- a/src/html_parser.hpp +++ b/src/html_parser.hpp @@ -29,7 +29,8 @@ namespace metaproxy_1 { int close_it) = 0; virtual void attribute(const char *tag, int tag_len, const char *attr, int attr_len, - const char *value, int val_len) = 0; + const char *value, int val_len, + const char *sep) = 0; virtual void closeTag(const char *tag, int tag_len) = 0; virtual void text(const char *value, int len) = 0; }; diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 2e4ae54..7df4d0b 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) const char *resp_expected = "HTTP/1.1 200 OK\r\n" - "Content-Length: 522\r\n" + "Content-Length: 520\r\n" "Content-Type: text/html\r\n" "Link: ; rel=absolute\r\n" "Link: ; rel=relative\r\n" @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) "xified" "" " An absolute link" - "" + "" " Another abs link" "" ""; diff --git a/src/test_html_parser.cpp b/src/test_html_parser.cpp index cdb266c..6f5c134 100644 --- a/src/test_html_parser.cpp +++ b/src/test_html_parser.cpp @@ -42,16 +42,17 @@ public: void openTagStart(const char *tag, int tag_len) { out += "<"; out.append(tag, tag_len); - } - + } + void attribute(const char *tag, int tag_len, const char *attr, int attr_len, - const char *value, int val_len) { + const char *value, int val_len, const char *sep) { out += " "; out.append(attr, attr_len); - out += "=\""; + out += "="; + out += sep; out.append(value, val_len); - out += "\""; + out += sep; } void anyTagEnd(const char *tag, int tag_len, int close_it) { if (close_it) @@ -76,7 +77,7 @@ BOOST_AUTO_TEST_CASE( test_html_parser_1 ) "some text" "
"; const char* expected = - "some text" + "some text" "
"; MyEvent e; hp.set_verbose(1); @@ -88,7 +89,7 @@ BOOST_AUTO_TEST_CASE( test_html_parser_1 ) std::cout << e.out << std::endl; BOOST_CHECK_EQUAL(std::string(expected), e.out); } - catch (std::exception & e) + catch (std::exception & e) { std::cout << e.what(); std::cout << std::endl;