else
{
while (i < end_pos && *i != wxT('>')) ++i;
- textBeginning = i+1;
+ textBeginning = i < end_pos ? i+1 : i;
}
}
else ++i;
wxString::const_iterator p = start;
// comments begin with "<!--" in HTML 4.0
- if ( p > end - 3 || *++p != '!' || *++p != '-' || *++p != '-' )
+ if ( end - start < 4 || *++p != '!' || *++p != '-' || *++p != '-' )
{
// not a comment at all
return false;
if ( wxHtmlParser::SkipCommentTag(pos, end) )
continue;
- size_t tg = Cache().size();
- Cache().push_back(wxHtmlCacheItem());
-
+ // Remember the starting tag position.
wxString::const_iterator stpos = pos++;
- Cache()[tg].Key = stpos;
+ // And look for the ending one.
int i;
for ( i = 0;
pos < end && i < (int)WXSIZEOF(tagBuffer) - 1 &&
}
tagBuffer[i] = wxT('\0');
- Cache()[tg].Name = new wxChar[i+1];
- memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
-
while (pos < end && *pos != wxT('>'))
++pos;
+ if ( pos == end )
+ {
+ // We didn't find a closing bracket, this is not a valid tag after
+ // all. Notice that we need to roll back pos to avoid creating an
+ // invalid iterator when "++pos" is done in the loop statement.
+ --pos;
+
+ continue;
+ }
+
+ // We have a valid tag, add it to the cache.
+ size_t tg = Cache().size();
+ Cache().push_back(wxHtmlCacheItem());
+ Cache()[tg].Key = stpos;
+ Cache()[tg].Name = new wxChar[i+1];
+ memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
+
if ((stpos+1) < end && *(stpos+1) == wxT('/')) // ending tag:
{
Cache()[tg].type = wxHtmlCacheItem::Type_EndingTag;
bool *hasEnding)
{
if (Cache().empty())
+ {
+ *end1 =
+ *end2 = inputEnd;
+ *hasEnding = true;
return;
+ }
if (Cache()[m_CachePos].Key != at)
{
test_gui_fonttest.o \
test_gui_image.o \
test_gui_rawbmp.o \
+ test_gui_htmlparser.o \
test_gui_htmlwindow.o \
test_gui_accelentry.o \
test_gui_menu.o \
test_gui_rawbmp.o: $(srcdir)/image/rawbmp.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/image/rawbmp.cpp
+test_gui_htmlparser.o: $(srcdir)/html/htmlparser.cpp $(TEST_GUI_ODEP)
+ $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmlparser.cpp
+
test_gui_htmlwindow.o: $(srcdir)/html/htmlwindow.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmlwindow.cpp
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/html/htmlparser.cpp
+// Purpose: wxHtmlParser tests
+// Author: Vadim Zeitlin
+// Created: 2011-01-13
+// RCS-ID: $Id$
+// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#if wxUSE_HTML
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#endif // WX_PRECOMP
+
+#include "wx/html/htmlpars.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class HtmlParserTestCase : public CppUnit::TestCase
+{
+public:
+ HtmlParserTestCase() { }
+
+private:
+ CPPUNIT_TEST_SUITE( HtmlParserTestCase );
+ CPPUNIT_TEST( Invalid );
+ CPPUNIT_TEST_SUITE_END();
+
+ void Invalid();
+
+ wxDECLARE_NO_COPY_CLASS(HtmlParserTestCase);
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( HtmlParserTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlParserTestCase, "HtmlParserTestCase" );
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+// Test that parsing invalid HTML simply fails but doesn't crash for example.
+void HtmlParserTestCase::Invalid()
+{
+ class NullParser : public wxHtmlParser
+ {
+ public:
+ virtual wxObject *GetProduct() { return NULL; }
+
+ protected:
+ virtual void AddText(const wxString& WXUNUSED(txt)) { }
+ };
+
+ NullParser p;
+ p.Parse("<");
+ p.Parse("<foo");
+ p.Parse("<!--");
+ p.Parse("<!---");
+}
+
+#endif //wxUSE_HTML
$(OBJS)\test_gui_fonttest.obj \\r
$(OBJS)\test_gui_image.obj \\r
$(OBJS)\test_gui_rawbmp.obj \\r
+ $(OBJS)\test_gui_htmlparser.obj \\r
$(OBJS)\test_gui_htmlwindow.obj \\r
$(OBJS)\test_gui_accelentry.obj \\r
$(OBJS)\test_gui_menu.obj \\r
$(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp\r
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp\r
\r
+$(OBJS)\test_gui_htmlparser.obj: .\html\htmlparser.cpp\r
+ $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmlparser.cpp\r
+\r
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp\r
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp\r
\r
$(OBJS)\test_gui_fonttest.o \\r
$(OBJS)\test_gui_image.o \\r
$(OBJS)\test_gui_rawbmp.o \\r
+ $(OBJS)\test_gui_htmlparser.o \\r
$(OBJS)\test_gui_htmlwindow.o \\r
$(OBJS)\test_gui_accelentry.o \\r
$(OBJS)\test_gui_menu.o \\r
$(OBJS)\test_gui_rawbmp.o: ./image/rawbmp.cpp\r
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
\r
+$(OBJS)\test_gui_htmlparser.o: ./html/htmlparser.cpp\r
+ $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
+\r
$(OBJS)\test_gui_htmlwindow.o: ./html/htmlwindow.cpp\r
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
\r
$(OBJS)\test_gui_fonttest.obj \\r
$(OBJS)\test_gui_image.obj \\r
$(OBJS)\test_gui_rawbmp.obj \\r
+ $(OBJS)\test_gui_htmlparser.obj \\r
$(OBJS)\test_gui_htmlwindow.obj \\r
$(OBJS)\test_gui_accelentry.obj \\r
$(OBJS)\test_gui_menu.obj \\r
$(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp\r
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp\r
\r
+$(OBJS)\test_gui_htmlparser.obj: .\html\htmlparser.cpp\r
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmlparser.cpp\r
+\r
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp\r
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp\r
\r
$(OBJS)\test_gui_fonttest.obj &\r
$(OBJS)\test_gui_image.obj &\r
$(OBJS)\test_gui_rawbmp.obj &\r
+ $(OBJS)\test_gui_htmlparser.obj &\r
$(OBJS)\test_gui_htmlwindow.obj &\r
$(OBJS)\test_gui_accelentry.obj &\r
$(OBJS)\test_gui_menu.obj &\r
$(OBJS)\test_gui_rawbmp.obj : .AUTODEPEND .\image\rawbmp.cpp\r
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
\r
+$(OBJS)\test_gui_htmlparser.obj : .AUTODEPEND .\html\htmlparser.cpp\r
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
+\r
$(OBJS)\test_gui_htmlwindow.obj : .AUTODEPEND .\html\htmlwindow.cpp\r
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
\r
font/fonttest.cpp
image/image.cpp
image/rawbmp.cpp
+ html/htmlparser.cpp
html/htmlwindow.cpp
menu/accelentry.cpp
menu/menu.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\html\htmlparser.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\html\htmlwindow.cpp\r
# End Source File\r
# Begin Source File\r
<File\r
RelativePath=".\controls\htmllboxtest.cpp">\r
</File>\r
+ <File\r
+ RelativePath=".\html\htmlparser.cpp">\r
+ </File>\r
<File\r
RelativePath=".\html\htmlwindow.cpp">\r
</File>\r
RelativePath=".\controls\htmllboxtest.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\html\htmlparser.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\html\htmlwindow.cpp"\r
>\r
RelativePath=".\controls\htmllboxtest.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\html\htmlparser.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\html\htmlwindow.cpp"\r
>\r