Author: diegoastiazaran Date: Thu Jul 25 13:14:45 2019 New Revision: 367045
URL: http://llvm.org/viewvc/llvm-project?rev=367045&view=rev Log: [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 Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367045&r1=367044&r2=367045&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original) +++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 13:14:45 2019 @@ -8,6 +8,7 @@ #include "Generators.h" #include "Representation.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -176,7 +177,7 @@ llvm::SmallString<16> HTMLTag::ToString( void TextNode::Render(llvm::raw_ostream &OS, int IndentationLevel) { if (Indented) OS.indent(IndentationLevel * 2); - OS << Text; + printHTMLEscaped(Text, OS); } void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) { Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367045&r1=367044&r2=367045&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original) +++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 25 13:14:45 2019 @@ -258,6 +258,15 @@ TEST(HTMLGeneratorTest, emitCommentHTML) Extended->Children.back()->Kind = "TextComment"; Extended->Children.back()->Text = " continues onto the next line."; + Top.Children.emplace_back(llvm::make_unique<CommentInfo>()); + CommentInfo *Entities = Top.Children.back().get(); + Entities->Kind = "ParagraphComment"; + Entities->Children.emplace_back(llvm::make_unique<CommentInfo>()); + Entities->Children.back()->Kind = "TextComment"; + Entities->Children.back()->Name = "ParagraphComment"; + Entities->Children.back()->Text = + " Comment with html entities: &, <, >, \", \'."; + I.Description.emplace_back(std::move(Top)); auto G = getHTMLGenerator(); @@ -285,6 +294,9 @@ TEST(HTMLGeneratorTest, emitCommentHTML) <p> Extended description that continues onto the next line. </p> + <p> + Comment with html entities: &, <, >, ", '. + </p> </div> </div> </div> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits