#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
+#include <yaz/matchstr.h>
#define SPACECHR " \t\r\n\f"
Rep();
~Rep();
int m_verbose;
+ bool nest;
};
}
mp::HTMLParser::Rep::Rep()
{
m_verbose = 0;
+ nest = true;
}
mp::HTMLParser::Rep::~Rep()
if (*cp++ != '<')
continue;
- if (*cp == '!')
+ if (nest && *cp == '!')
{
int i;
tagText(event, text_start, cp - 1);
cp += i;
text_start = cp;
}
- else if (*cp == '?')
+ else if (nest && *cp == '?')
{
int i;
tagText(event, text_start, cp - 1);
tagText(event, text_start, cp - 1);
i = skipName(++cp);
+
+ if (!nest)
+ {
+ if (i == 6 && !yaz_strncasecmp(cp, "script", i))
+ nest = true;
+ else
+ {
+ text_start = cp - 1; // points to '/'
+ continue;
+ }
+ }
event.closeTag(cp, i);
if (m_verbose)
printf("------ tag close %.*s\n", i, cp);
cp += i;
text_start = cp;
}
- else if (isAlpha(*cp))
+ else if (nest && isAlpha(*cp))
{
int i, j;
tagText(event, text_start, cp - 1);
printf("------ tag open %.*s\n", i, cp);
j = tagAttrs(event, cp, i, cp + i);
j += tagEnd(event, cp, i, cp + i + j);
+
+ if (i == 6 && !yaz_strncasecmp(cp, "script", i))
+ nest = false;
+
cp += i + j;
text_start = cp;
}
{
try
{
- std::cout << "Running non-xml config test case" << std::endl;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
"</style>"
"</head>"
"<script>var jslink=\"http://targetsite/webservice.xml\";"
+ "for (i = 0; i<foo; i++) ;\n"
"var some=\"foo\"; foo=1;"
"</script>"
"<body>"
const char *resp_expected =
"HTTP/1.1 200 OK\r\n"
- "Content-Length: 605\r\n"
+ "Content-Length: 631\r\n"
"Content-Type: text/html\r\n"
"Link: <http://proxyhost/proxypath/targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
"</style>"
"</head>"
"<script>var jslink=\"http://proxyhost/proxypath/targetsite/webservice.xml\";"
+ "for (i = 0; i<foo; i++) ;\n"
"var some=\"bar\"; foo=1;"
"</script>"
"<body>"
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
- std::cout << "Got result:\n" << "\n";
+ std::cout << "Got result:\n";
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);
}
}
-
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
{
try
{
- std::cout << "Running non-xml config test case" << std::endl;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
- std::cout << "Got result:\n" << "\n";
+ std::cout << "Got result:\n";
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);
out.append(value, len);
}
};
-
+#if 0
BOOST_AUTO_TEST_CASE( test_html_parser_1 )
{
try
BOOST_CHECK (false);
}
}
+#endif
+BOOST_AUTO_TEST_CASE( test_html_parser_7 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "<html><script>x=1; for (i=0;i<x;i++) ;\nx=2;\n</script></html>";
+
+ const char* expected = html;
+ MyEvent e;
+ hp.set_verbose(1);
+ 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);
+ }
+}
/*