Skip to content

Commit 95d4ef0

Browse files
committed
Prevent unsupported HTML tags from breaking the navigation tree
1 parent b1bbfe8 commit 95d4ef0

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/docnode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ class DocTitle : public DocCompoundNode
611611
void parse();
612612
void parseFromString(DocNodeVariant *,const QCString &title);
613613
bool hasTitle() const { return !children().empty(); }
614+
bool isEmpty() const { return !hasTitle(); }
614615

615616
private:
616617
};
@@ -1481,6 +1482,10 @@ class DocNodeAST : public IDocNodeAST
14811482
{
14821483
return std::get<DocText>(root).isEmpty();
14831484
}
1485+
else if (std::holds_alternative<DocTitle>(root))
1486+
{
1487+
return std::get<DocTitle>(root).isEmpty();
1488+
}
14841489
return false;
14851490
}
14861491
DocNodeVariant root;

src/docparser.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,58 @@ IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf,
20502050
return ast;
20512051
}
20522052

2053+
IDocNodeASTPtr validatingParseTitle(IDocParser &parserIntf,const QCString &fileName,int lineNr,const QCString &input)
2054+
{
2055+
DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2056+
assert(parser!=nullptr);
2057+
if (parser==nullptr) return nullptr;
2058+
2059+
// set initial token
2060+
parser->context.token = parser->tokenizer.resetToken();
2061+
2062+
//printf("------------ input ---------\n%s\n"
2063+
// "------------ end input -----\n",input);
2064+
parser->context.context = "";
2065+
parser->context.fileName = fileName;
2066+
parser->context.relPath = "";
2067+
parser->context.memberDef = nullptr;
2068+
while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2069+
while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2070+
while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2071+
parser->context.inSeeBlock = FALSE;
2072+
parser->context.xmlComment = FALSE;
2073+
parser->context.insideHtmlLink = FALSE;
2074+
parser->context.includeFileText = "";
2075+
parser->context.includeFileOffset = 0;
2076+
parser->context.includeFileLength = 0;
2077+
parser->context.isExample = FALSE;
2078+
parser->context.exampleName = "";
2079+
parser->context.hasParamCommand = FALSE;
2080+
parser->context.hasReturnCommand = FALSE;
2081+
parser->context.retvalsFound.clear();
2082+
parser->context.paramsFound.clear();
2083+
parser->context.searchUrl="";
2084+
parser->context.lang = SrcLangExt::Unknown;
2085+
parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2086+
parser->context.autolinkSupport = false;
2087+
2088+
auto ast = std::make_unique<DocNodeAST>(DocTitle(parser,nullptr));
2089+
2090+
if (!input.isEmpty())
2091+
{
2092+
// build abstract syntax tree from title string
2093+
std::get<DocTitle>(ast->root).parseFromString(nullptr,input);
2094+
2095+
if (Debug::isFlagSet(Debug::PrintTree))
2096+
{
2097+
// pretty print the result
2098+
std::visit(PrintDocVisitor{},ast->root);
2099+
}
2100+
}
2101+
2102+
return ast;
2103+
}
2104+
20532105
IDocNodeASTPtr validatingParseText(IDocParser &parserIntf,const QCString &input)
20542106
{
20552107
DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);

src/docparser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf,const QCString &fileNam
9393
*/
9494
IDocNodeASTPtr validatingParseText(IDocParser &parser,const QCString &input);
9595

96+
97+
/*! Main entry point for parsing titles. These allow limited markup commands */
98+
IDocNodeASTPtr validatingParseTitle(IDocParser &parserIntf,const QCString &fileName,int lineNr,
99+
const QCString &input);
100+
101+
96102
IDocNodeASTPtr createRef(IDocParser &parser,const QCString &target,const QCString &context, const QCString &srcFile = "", int srcLine = -1);
97103

98104
//--------------------------------------------------------------------------------

src/util.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5938,8 +5938,7 @@ QCString parseCommentAsHtml(const Definition *scope,const MemberDef *member,cons
59385938
return it->second;
59395939
}
59405940
auto parser { createDocParser() };
5941-
auto ast { validatingParseDoc(*parser.get(),fileName,lineNr,scope,member,doc,false,false,
5942-
QCString(),true,false,Config_getBool(MARKDOWN_SUPPORT),false) };
5941+
auto ast { validatingParseTitle(*parser.get(),fileName,lineNr,doc) };
59435942
auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
59445943
QCString result;
59455944
if (astImpl)

0 commit comments

Comments
 (0)