1919
2020#include " html-writer.hh"
2121
22+ #include " cwe-name-lookup.hh"
2223#include " deflookup.hh"
2324#include " regex.hh"
2425
@@ -195,12 +196,16 @@ void linkifyShellCheckMsg(std::string *pMsg)
195196 " \\ 1SC\\ 2\\ 3</a>" );
196197}
197198
198- void printCweLink (std::ostream &str, const int cwe)
199+ void printCweLink (std::ostream &str, const int cwe, const std::string &cweName )
199200{
200201 str << " <a href=\" https://cwe.mitre.org/data/definitions/"
201- << cwe << " .html\" "
202- << " title=\" definition of CWE-"
203- << cwe << " by MITRE\" >"
202+ << cwe << " .html\" title=\" " ;
203+ if (cweName.empty ())
204+ str << " definition of CWE-" << cwe << " by MITRE" ;
205+ else
206+ str << " CWE-" << cwe << " : " << cweName;
207+
208+ str << " \" >"
204209 << " CWE-" << cwe
205210 << " </a>" ;
206211}
@@ -303,11 +308,12 @@ struct HtmlWriter::Private {
303308 HtmlWriterCore core;
304309 TScanProps scanProps;
305310 const std::string defUrlTemplate;
306- unsigned defCnt;
307- DefLookup *baseLookup;
311+ unsigned defCnt = 0U ;
312+ DefLookup *baseLookup = nullptr ;
308313 RE checkerIgnRegex;
309314 std::string newDefMsg;
310315 std::string plainTextUrl;
316+ const CweNameLookup *cweNames = nullptr ;
311317
312318 Private (
313319 std::ostream &str_,
@@ -316,9 +322,7 @@ struct HtmlWriter::Private {
316322 const std::string &spPlacement_):
317323 str (str_),
318324 core (str_, titleFallback_, spPlacement_),
319- defUrlTemplate (defUrlTemplate_),
320- defCnt (0 ),
321- baseLookup (0 )
325+ defUrlTemplate (defUrlTemplate_)
322326 {
323327 if (!defUrlTemplate.empty ())
324328 // just make sure that the format string is correct
@@ -394,6 +398,11 @@ void HtmlWriter::setPlainTextUrl(const std::string &url)
394398 d->plainTextUrl = url;
395399}
396400
401+ void HtmlWriter::setCweNameLookup (const CweNameLookup *cweNames)
402+ {
403+ d->cweNames = cweNames;
404+ }
405+
397406void HtmlWriter::Private::writeLinkToDetails (const Defect &def)
398407{
399408 const int defId = def.defectId ;
@@ -451,13 +460,19 @@ void HtmlWriter::handleDef(const Defect &def)
451460
452461 d->str << " <b>Error: <span style='background: #C0FF00;'>"
453462 << HtmlLib::escapeTextInline (def.checker ) << " </span>" ;
454- if (def.cwe ) {
463+
464+ const int cwe = def.cwe ;
465+ if (cwe) {
466+ std::string cweName;
467+ if (d->cweNames )
468+ cweName = d->cweNames ->lookup (cwe);
455469 d->str << " (" ;
456- printCweLink (d->str , def. cwe );
470+ printCweLink (d->str , cwe, cweName );
457471 d->str << " )" ;
458472 }
459473 else
460474 d->str << HtmlLib::escapeTextInline (def.annotation );
475+
461476 d->str << " :</b>" ;
462477
463478 d->writeLinkToDetails (def);
0 commit comments