Careful check of </script> termination
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 10 Sep 2013 12:18:54 +0000 (14:18 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 10 Sep 2013 12:18:54 +0000 (14:18 +0200)
src/html_parser.cpp
src/test_html_parser.cpp

index 1a403d4..3f1a4f4 100644 (file)
@@ -270,11 +270,13 @@ void mp::HTMLParser::Rep::parse_str(HTMLParserEvent &event, const char *cp)
             if (!nest)
             {
                 if (i == 6 && !yaz_strncasecmp(cp, "script", i))
-                    nest = true;
-                else
                 {
-                    continue;
+                    int ws = skipSpace(cp + 6);
+                    if (cp[ws + 6] == '>')
+                        nest = true; /* really terminated */
                 }
+                if (!nest)
+                    continue;
             }
             tagText(event, text_start, cp - 2);
             event.closeTag(cp, i);
index dd66b57..2b23dde 100644 (file)
@@ -70,7 +70,7 @@ public:
         out.append(value, len);
     }
 };
-#if 0
+
 BOOST_AUTO_TEST_CASE( test_html_parser_1 )
 {
     try
@@ -270,18 +270,20 @@ BOOST_AUTO_TEST_CASE( test_html_parser_6 )
         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>";
+            "<html><Script>x=1; for (i=0;i<x;i++) </y>;"
+            "</SCRIPT ;>"
+            "</1>\nx=2;\n</Script></html>";
 
         const char* expected = html;
         MyEvent e;
-        hp.set_verbose(1);
+        hp.set_verbose(0);
         hp.parse(e, html);
 
         BOOST_CHECK_EQUAL(std::string(expected), e.out);