Skip to content

Commit 597b3fd

Browse files
committedJul 25, 2019
[clang-doc] Fix html entities in rendered text
Replace &, <, >, ", and ' with their corresponding html entities in text rendered by HTML generator. Differential Revision: https://reviews.llvm.org/D65107 llvm-svn: 367045
1 parent cde00c0 commit 597b3fd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎clang-tools-extra/clang-doc/HTMLGenerator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Generators.h"
1010
#include "Representation.h"
11+
#include "llvm/ADT/StringExtras.h"
1112
#include "llvm/ADT/StringRef.h"
1213
#include "llvm/Support/FileSystem.h"
1314
#include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@ llvm::SmallString<16> HTMLTag::ToString() const {
176177
void TextNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
177178
if (Indented)
178179
OS.indent(IndentationLevel * 2);
179-
OS << Text;
180+
printHTMLEscaped(Text, OS);
180181
}
181182

182183
void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {

‎clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ TEST(HTMLGeneratorTest, emitCommentHTML) {
258258
Extended->Children.back()->Kind = "TextComment";
259259
Extended->Children.back()->Text = " continues onto the next line.";
260260

261+
Top.Children.emplace_back(llvm::make_unique<CommentInfo>());
262+
CommentInfo *Entities = Top.Children.back().get();
263+
Entities->Kind = "ParagraphComment";
264+
Entities->Children.emplace_back(llvm::make_unique<CommentInfo>());
265+
Entities->Children.back()->Kind = "TextComment";
266+
Entities->Children.back()->Name = "ParagraphComment";
267+
Entities->Children.back()->Text =
268+
" Comment with html entities: &, <, >, \", \'.";
269+
261270
I.Description.emplace_back(std::move(Top));
262271

263272
auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@ TEST(HTMLGeneratorTest, emitCommentHTML) {
285294
<p>
286295
Extended description that continues onto the next line.
287296
</p>
297+
<p>
298+
Comment with html entities: &amp;, &lt;, &gt;, &quot;, &apos;.
299+
</p>
288300
</div>
289301
</div>
290302
</div>

0 commit comments

Comments
 (0)