Aard: Better isolate the cards from each other; protect against broken HTML

This commit is contained in:
Tvangeste 2013-07-04 15:58:28 +02:00
parent d9bcb2ea43
commit 6a20b9765a

14
aard.cc
View file

@ -474,7 +474,19 @@ void AardDictionary::loadArticle( quint32 address,
else
articleText = string( QObject::tr( "Article decoding error" ).toUtf8().constData() );
articleText = "<div class=\"aard\">" + articleText + "</div>";
// See Issue #271: A mechanism to clean-up invalid HTML cards.
string cleaner = "</font>""</font>""</font>""</font>""</font>""</font>"
"</font>""</font>""</font>""</font>""</font>""</font>"
"</b></b></b></b></b></b></b></b>"
"</i></i></i></i></i></i></i></i>"
"</a></a></a></a></a></a></a></a>";
static QRegExp self_closing_divs( "(<div\\s[^>]*)/>", Qt::CaseInsensitive ); // <div ... />
articleText = string( "<div class=\"aard\">" )
// protect against <div/> which breaks formatting
+ QString::fromUtf8( ( articleText ).c_str() ).replace( self_closing_divs, "\\1></div>").toUtf8().data()
+ cleaner + "</div>";
}
QString const& AardDictionary::getDescription()