Guard getTagType and isCloseTag

Add guard clauses for getTagType and isCloseTag to avoid crashing if the string is empty.

CCBUG: 468448
This commit is contained in:
James Graham
2023-04-15 07:59:05 +00:00
parent d83b31fd86
commit f8040a1bf6

View File

@@ -280,6 +280,9 @@ void TextHandler::nextTokenType()
QString TextHandler::getTagType() const
{
if (m_nextToken.isEmpty()) {
return QString();
}
const int tagTypeStart = m_nextToken[1] == u'/' ? 2 : 1;
const int tagTypeEnd = m_nextToken.indexOf(TextRegex::endTagType, tagTypeStart);
return m_nextToken.mid(tagTypeStart, tagTypeEnd - tagTypeStart);
@@ -287,6 +290,9 @@ QString TextHandler::getTagType() const
bool TextHandler::isCloseTag() const
{
if (m_nextToken.isEmpty()) {
return false;
}
return m_nextToken[1] == u'/';
}