Skip to content

Commit 5e2edda

Browse files
committed
html-writer: provide links to CWE definitions
1 parent a826060 commit 5e2edda

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/html-writer.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ void linkifyShellCheckMsg(std::string *pMsg)
195195
"\\1SC\\2\\3</a>");
196196
}
197197

198+
void printCweLink(std::ostream &str, const int cwe)
199+
{
200+
str << "<a href=\"https://cwe.mitre.org/data/definitions/"
201+
<< cwe << ".html\""
202+
<< " title=\"definition of CWE-"
203+
<< cwe << " by MITRE\">"
204+
<< "CWE-" << cwe
205+
<< "</a>";
206+
}
207+
198208
class HtmlWriterCore {
199209
public:
200210
HtmlWriterCore(
@@ -441,8 +451,11 @@ void HtmlWriter::handleDef(const Defect &def)
441451

442452
d->str << "<b>Error: <span style='background: #C0FF00;'>"
443453
<< HtmlLib::escapeTextInline(def.checker) << "</span>";
444-
if (def.cwe)
445-
d->str << " (CWE-" << def.cwe << ")";
454+
if (def.cwe) {
455+
d->str << " (";
456+
printCweLink(d->str, def.cwe);
457+
d->str << ")";
458+
}
446459
else
447460
d->str << HtmlLib::escapeTextInline(def.annotation);
448461
d->str << ":</b>";

0 commit comments

Comments
 (0)