From: Dmitri Gribenko Date: Wed, 1 Aug 2012 00:21:12 +0000 (+0000) Subject: Comment to HTML conversion: escape HTML special characters in command arguments X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59500fec689f7def27bb83bd21e19417ad527906;p=clang Comment to HTML conversion: escape HTML special characters in command arguments git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161094 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/annotate-comments.cpp b/test/Index/annotate-comments.cpp index b1b72ff573..60b8748f10 100644 --- a/test/Index/annotate-comments.cpp +++ b/test/Index/annotate-comments.cpp @@ -341,15 +341,18 @@ void comment_to_html_conversion_25(); /// \a Aaa \e Bbb \em Ccc void comment_to_html_conversion_26(); -/// \\ \@ \& \$ \# \< \> \% \" \. \:: +/// \a 1<2 \e 3<4 \em 5<6 \param 7<8 aaa \tparam 9<10 bbb void comment_to_html_conversion_27(); -/// & < > " +/// \\ \@ \& \$ \# \< \> \% \" \. \:: void comment_to_html_conversion_28(); -/// 0<i +/// & < > " void comment_to_html_conversion_29(); +/// 0<i +void comment_to_html_conversion_30(); + #endif // RUN: rm -rf %t @@ -706,7 +709,24 @@ void comment_to_html_conversion_29(); // CHECK-NEXT: (CXComment_InlineCommand CommandName=[e] RenderEmphasized Arg[0]=Bbb) // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) // CHECK-NEXT: (CXComment_InlineCommand CommandName=[em] RenderEmphasized Arg[0]=Ccc)))] -// CHECK: annotate-comments.cpp:345:6: FunctionDecl=comment_to_html_conversion_27:{{.*}} FullCommentAsHTML=[

\ @ & $ # < > % " . ::

] +// CHECK: annotate-comments.cpp:345:6: FunctionDecl=comment_to_html_conversion_27:{{.*}} FullCommentAsHTML=[

1<2 3<4 5<6

9<10
bbb
7<8
aaa
] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) +// CHECK-NEXT: (CXComment_InlineCommand CommandName=[a] RenderEmphasized Arg[0]=1<2) +// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) +// CHECK-NEXT: (CXComment_InlineCommand CommandName=[e] RenderEmphasized Arg[0]=3<4) +// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) +// CHECK-NEXT: (CXComment_InlineCommand CommandName=[em] RenderEmphasized Arg[0]=5<6) +// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)) +// CHECK-NEXT: (CXComment_ParamCommand in implicitly ParamName=[7<8] ParamIndex=Invalid +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ aaa ]))) +// CHECK-NEXT: (CXComment_TParamCommand ParamName=[9<10] ParamPosition=Invalid +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ bbb]))))] +// CHECK: annotate-comments.cpp:348:6: FunctionDecl=comment_to_html_conversion_28:{{.*}} FullCommentAsHTML=[

\ @ & $ # < > % " . ::

] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -732,7 +752,7 @@ void comment_to_html_conversion_29(); // CHECK-NEXT: (CXComment_Text Text=[.]) // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) // CHECK-NEXT: (CXComment_Text Text=[::])))] -// CHECK: annotate-comments.cpp:348:6: FunctionDecl=comment_to_html_conversion_28:{{.*}} FullCommentAsHTML=[

& < > "

] +// CHECK: annotate-comments.cpp:351:6: FunctionDecl=comment_to_html_conversion_29:{{.*}} FullCommentAsHTML=[

& < > "

] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -744,7 +764,7 @@ void comment_to_html_conversion_29(); // CHECK-NEXT: (CXComment_Text Text=[>]) // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) // CHECK-NEXT: (CXComment_Text Text=["])))] -// CHECK: annotate-comments.cpp:351:6: FunctionDecl=comment_to_html_conversion_29:{{.*}} FullCommentAsHTML=[

0<i

] +// CHECK: annotate-comments.cpp:354:6: FunctionDecl=comment_to_html_conversion_30:{{.*}} FullCommentAsHTML=[

0<i

] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 9bdab61942..0d971c390a 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -450,21 +450,29 @@ void CommentASTToHTMLConverter::visitInlineCommandComment( switch (C->getRenderKind()) { case InlineCommandComment::RenderNormal: - for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) - Result << C->getArgText(i) << " "; + for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) { + appendToResultWithHTMLEscaping(C->getArgText(i)); + Result << " "; + } return; case InlineCommandComment::RenderBold: assert(C->getNumArgs() == 1); - Result << "" << Arg0 << ""; + Result << ""; + appendToResultWithHTMLEscaping(Arg0); + Result << ""; return; case InlineCommandComment::RenderMonospaced: assert(C->getNumArgs() == 1); - Result << "" << Arg0 << ""; + Result << ""; + appendToResultWithHTMLEscaping(Arg0); + Result<< ""; return; case InlineCommandComment::RenderEmphasized: assert(C->getNumArgs() == 1); - Result << "" << Arg0 << ""; + Result << ""; + appendToResultWithHTMLEscaping(Arg0); + Result << ""; return; } } @@ -537,7 +545,8 @@ void CommentASTToHTMLConverter::visitParamCommandComment( } else Result << "
"; - Result << C->getParamName() << "
"; + appendToResultWithHTMLEscaping(C->getParamName()); + Result << ""; if (C->isParamIndexValid()) { Result << "
"; - Result << C->getParamName() << ""; + appendToResultWithHTMLEscaping(C->getParamName()); + Result << ""; if (C->isPositionValid()) { if (C->getDepth() == 1)