From 2ee83c18eef23c98fd4e97d581401be193fdf41f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 19 Aug 2013 13:40:04 +0200 Subject: [PATCH] HTML parser stops eating tag when <-char is met --- src/html_parser.cpp | 6 +++--- src/test_html_parser.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/html_parser.cpp b/src/html_parser.cpp index 3641195..fba5595 100644 --- a/src/html_parser.cpp +++ b/src/html_parser.cpp @@ -95,7 +95,7 @@ static int skipSpace(const char *cp) static int skipName(const char *cp) { int i; - for (i = 0; cp[i] && !strchr(SPACECHR "/>=", cp[i]); i++) + for (i = 0; cp[i] && !strchr(SPACECHR "/>=<", cp[i]); i++) ; return i; } @@ -146,7 +146,7 @@ int mp::HTMLParser::Rep::tagAttrs(HTMLParserEvent &event, const char *cp) { int i = skipSpace(cp); - while (cp[i] && cp[i] != '>' && cp[i] != '/') + while (cp[i] && cp[i] != '>' && cp[i] != '/' && cp[i] != '<') { const char *attr_name = cp + i; int attr_len; @@ -174,7 +174,7 @@ int mp::HTMLParser::Rep::tagEnd(HTMLParserEvent &event, { int i = 0; int close_it = 0; - for (; cp[i] && cp[i] != '/' && cp[i] != '>'; i++) + for (; cp[i] && cp[i] != '/' && cp[i] != '>' && cp[i] != '<'; i++) ; if (i > 0) { diff --git a/src/test_html_parser.cpp b/src/test_html_parser.cpp index 3604436..6e0ea4c 100644 --- a/src/test_html_parser.cpp +++ b/src/test_html_parser.cpp @@ -241,6 +241,36 @@ BOOST_AUTO_TEST_CASE( test_html_parser_5 ) } } +BOOST_AUTO_TEST_CASE( test_html_parser_6 ) +{ + try + { + mp::HTMLParser hp; + const char* html = + ""; + + const char* expected = html; + MyEvent e; + hp.set_verbose(0); + hp.parse(e, html); + + BOOST_CHECK_EQUAL(std::string(expected), e.out); + if (std::string(expected) != e.out) + { + std::cout << "Expected" << std::endl; + std::cout << expected << std::endl; + std::cout << "Got" << std::endl; + std::cout << e.out << std::endl; + } + } + catch (std::exception & e) + { + std::cout << e.what(); + std::cout << std::endl; + BOOST_CHECK (false); + } +} + /* * Local variables: -- 1.7.10.4