]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed wxHTML parser to not assert on invalid HTML input (unclosed tags)
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 15 Jan 2008 12:13:54 +0000 (12:13 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 15 Jan 2008 12:13:54 +0000 (12:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51223 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/html/htmltag.h
src/html/htmltag.cpp

index 40bcf488716d3eb7b046a7ed41842cb9a7f7bba5..38533338666499ad10539a386140e5fb22070cba 100644 (file)
@@ -126,13 +126,11 @@ public:
     // returns ending position of _internal_ block of text as iterator
     // into parser's source string (see wxHtmlParser::GetSource()):
     // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
     // returns ending position of _internal_ block of text as iterator
     // into parser's source string (see wxHtmlParser::GetSource()):
     // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
-    wxString::const_iterator GetEndIter1() const
-        { wxASSERT(m_hasEnding); return m_End1; }
+    wxString::const_iterator GetEndIter1() const { return m_End1; }
     // returns end position 2 as iterator
     // into parser's source string (see wxHtmlParser::GetSource()):
     // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
     // returns end position 2 as iterator
     // into parser's source string (see wxHtmlParser::GetSource()):
     // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
-    wxString::const_iterator GetEndIter2() const
-        { wxASSERT(m_hasEnding); return m_End2; }
+    wxString::const_iterator GetEndIter2() const { return m_End2; }
 
 #if WXWIN_COMPATIBILITY_2_8
     // use GetBeginIter(), GetEndIter1() and GetEndIter2() instead
 
 #if WXWIN_COMPATIBILITY_2_8
     // use GetBeginIter(), GetEndIter1() and GetEndIter2() instead
index d3e277c1509885adf0fd6ec17e6dbcba49f56eff..cd172656983647c5995139c5eac3b8dc16645f9d 100644 (file)
@@ -246,9 +246,27 @@ void wxHtmlTagsCache::QueryTag(const wxString::const_iterator& at,
         }
         while (Cache()[m_CachePos].Key != at);
     }
         }
         while (Cache()[m_CachePos].Key != at);
     }
-    *end1 = Cache()[m_CachePos].End1;
-    *end2 = Cache()[m_CachePos].End2;
-    *hasEnding = (Cache()[m_CachePos].type == wxHtmlCacheItem::Type_Normal);
+
+    switch ( Cache()[m_CachePos].type )
+    {
+        case wxHtmlCacheItem::Type_Normal:
+            *end1 = Cache()[m_CachePos].End1;
+            *end2 = Cache()[m_CachePos].End2;
+            *hasEnding = true;
+            break;
+
+        case wxHtmlCacheItem::Type_EndingTag:
+            wxFAIL_MSG("QueryTag called for ending tag - can't be");
+            // but if it does happen, fall through, better than crashing
+
+        case wxHtmlCacheItem::Type_NoMatchingEndingTag:
+            // If input HTML is invalid and there's no closing tag for this
+            // one, pretend that it runs all the way to the end of input
+            *end1 = inputEnd;
+            *end2 = inputEnd;
+            *hasEnding = false;
+            break;
+    }
 }
 
 
 }