diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2014-04-22 10:59:13 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2014-04-22 10:59:13 +0000 |
commit | 93043620bc63102f3316bfbec4aab33d06df334b (patch) | |
tree | 8f539a202bc6bdb17f37dbb365198ed4e6e1ae26 /clang/test | |
parent | 6e647c13e451dc57f01e96d1d1dafc8c9b406959 (diff) | |
download | bcm5719-llvm-93043620bc63102f3316bfbec4aab33d06df334b.tar.gz bcm5719-llvm-93043620bc63102f3316bfbec4aab33d06df334b.zip |
Comment parsing: in the generated XML file, mark HTML that is safe to pass
through to the output even if the input comment comes from an untrusted source
Attribute filtering is currently based on a blacklist, which right now includes
all event handler attributes (they contain JavaScipt code). It should be
switched to a whitelist, but going over all of the HTML5 spec requires a
significant amount of time.
llvm-svn: 206882
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Index/Inputs/CommentXML/valid-function-02.xml | 11 | ||||
-rw-r--r-- | clang/test/Index/comment-to-html-xml-conversion.cpp | 32 | ||||
-rw-r--r-- | clang/test/Sema/warn-documentation.cpp | 13 |
3 files changed, 53 insertions, 3 deletions
diff --git a/clang/test/Index/Inputs/CommentXML/valid-function-02.xml b/clang/test/Index/Inputs/CommentXML/valid-function-02.xml index 989d6a7c143..98e4fd1c1ed 100644 --- a/clang/test/Index/Inputs/CommentXML/valid-function-02.xml +++ b/clang/test/Index/Inputs/CommentXML/valid-function-02.xml @@ -1,5 +1,14 @@ <?xml version="1.0" encoding="utf-8"?> <Function> <Name>aaa</Name> -<Abstract><Para>Aaa <bold>bbb</bold> <monospaced>ccc</monospaced> <emphasized>ddd</emphasized>.</Para></Abstract> +<Abstract> + <Para>Aaa + <bold>bbb</bold> + <monospaced>ccc</monospaced> + <emphasized>ddd</emphasized> + <rawHTML><eee></rawHTML> + <rawHTML isSafeToPassThrough="0"><fff></rawHTML> + <rawHTML isSafeToPassThrough="1"><ggg></rawHTML>. + </Para> +</Abstract> </Function> diff --git a/clang/test/Index/comment-to-html-xml-conversion.cpp b/clang/test/Index/comment-to-html-xml-conversion.cpp index 327fa644832..590e1871974 100644 --- a/clang/test/Index/comment-to-html-xml-conversion.cpp +++ b/clang/test/Index/comment-to-html-xml-conversion.cpp @@ -472,7 +472,7 @@ void test_full_comment_1(int x1, int x2); /// <br><a href="http://example.com/">Aaa</a> void comment_to_html_conversion_24(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_24:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <br><a href="http://example.com/">Aaa</a></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_24</Name><USR>c:@F@comment_to_html_conversion_24#</USR><Declaration>void comment_to_html_conversion_24()</Declaration><Abstract><Para> <rawHTML><![CDATA[<br>]]></rawHTML><rawHTML><![CDATA[<a href="http://example.com/">]]></rawHTML>Aaa<rawHTML></a></rawHTML></Para></Abstract></Function>] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_24:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <br><a href="http://example.com/">Aaa</a></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_24</Name><USR>c:@F@comment_to_html_conversion_24#</USR><Declaration>void comment_to_html_conversion_24()</Declaration><Abstract><Para> <rawHTML isSafeToPassThrough="1"><![CDATA[<br>]]></rawHTML><rawHTML isSafeToPassThrough="1"><![CDATA[<a href="http://example.com/">]]></rawHTML>Aaa<rawHTML isSafeToPassThrough="1"></a></rawHTML></Para></Abstract></Function>] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -678,7 +678,7 @@ void comment_to_html_conversion_33(); /// <em>0<i</em> void comment_to_html_conversion_34(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_34:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <em>0<i</em></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_34</Name><USR>c:@F@comment_to_html_conversion_34#</USR><Declaration>void comment_to_html_conversion_34()</Declaration><Abstract><Para> <rawHTML><![CDATA[<em>]]></rawHTML>0<i<rawHTML></em></rawHTML></Para></Abstract></Function>] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_34:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <em>0<i</em></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_34</Name><USR>c:@F@comment_to_html_conversion_34#</USR><Declaration>void comment_to_html_conversion_34()</Declaration><Abstract><Para> <rawHTML isSafeToPassThrough="1"><![CDATA[<em>]]></rawHTML>0<i<rawHTML isSafeToPassThrough="1"></em></rawHTML></Para></Abstract></Function>] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph @@ -853,6 +853,34 @@ enum class comment_to_xml_conversion_17 { // CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:3: EnumConstantDecl=comment_to_xml_conversion_18:{{.*}} FullCommentAsXML=[<Variable file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="3"><Name>comment_to_xml_conversion_18</Name><USR>c:@E@comment_to_xml_conversion_17@comment_to_xml_conversion_18</USR><Declaration>comment_to_xml_conversion_18</Declaration><Abstract><Para> Aaa.</Para></Abstract></Variable>] }; +/// <a href="http://example.org/"> +void comment_to_xml_conversion_unsafe_html_01(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_01:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_01</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_01#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_01()</Declaration><Abstract><Para> <rawHTML><![CDATA[<a href="http://example.org/">]]></rawHTML></Para></Abstract></Function>] + +/// <a href="http://example.org/"><em>Aaa</em> +void comment_to_xml_conversion_unsafe_html_02(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_02:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_02</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_02#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_02()</Declaration><Abstract><Para> <rawHTML><![CDATA[<a href="http://example.org/">]]></rawHTML><rawHTML isSafeToPassThrough="1"><![CDATA[<em>]]></rawHTML>Aaa<rawHTML isSafeToPassThrough="1"></em></rawHTML></Para></Abstract></Function>] + +/// <em>Aaa +void comment_to_xml_conversion_unsafe_html_03(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_03:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_03</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_03#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_03()</Declaration><Abstract><Para> <rawHTML><![CDATA[<em>]]></rawHTML>Aaa</Para></Abstract></Function>] + +/// <em>Aaa</b></em> +void comment_to_xml_conversion_unsafe_html_04(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_04:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_04</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_04#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_04()</Declaration><Abstract><Para> <rawHTML isSafeToPassThrough="1"><![CDATA[<em>]]></rawHTML>Aaa<rawHTML></b></rawHTML><rawHTML isSafeToPassThrough="1"></em></rawHTML></Para></Abstract></Function>] + +/// <em>Aaa</em></b> +void comment_to_xml_conversion_unsafe_html_05(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_05:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_05</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_05#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_05()</Declaration><Abstract><Para> <rawHTML isSafeToPassThrough="1"><![CDATA[<em>]]></rawHTML>Aaa<rawHTML isSafeToPassThrough="1"></em></rawHTML><rawHTML></b></rawHTML></Para></Abstract></Function>] + +/// </table> +void comment_to_xml_conversion_unsafe_html_06(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_06:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_06</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_06#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_06()</Declaration><Abstract><Para> <rawHTML></table></rawHTML></Para></Abstract></Function>] + +/// <div onclick="alert('meow');">Aaa</div> +void comment_to_xml_conversion_unsafe_html_07(); +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_unsafe_html_07:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_unsafe_html_07</Name><USR>c:@F@comment_to_xml_conversion_unsafe_html_07#</USR><Declaration>void comment_to_xml_conversion_unsafe_html_07()</Declaration><Abstract><Para> <rawHTML><![CDATA[<div onclick="alert('meow');">]]></rawHTML>Aaa<rawHTML></div></rawHTML></Para></Abstract></Function>] + //===--- // Check that we attach comments from the base class to derived classes if they don't have a comment. // rdar://13647476 diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index ed25d949f55..4375cfcf560 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -4,35 +4,43 @@ // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s | FileCheck %s -check-prefix=WRONG // WRONG-NOT: CommentXMLInvalid +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{expected quoted string after equals sign}} /// <a href=> int test_html1(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{expected quoted string after equals sign}} /// <a href==> int test_html2(int); +// expected-warning@+3 {{HTML tag 'a' requires an end tag}} // expected-warning@+2 {{expected quoted string after equals sign}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a href= blah int test_html3(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a => int test_html4(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a "aaa"> int test_html5(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" => int test_html6(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" "aaa"> int test_html7(int); +// expected-warning@+2 {{HTML tag 'a' requires an end tag}} // expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" = int test_html8(int); @@ -67,6 +75,8 @@ int test_html_nesting3(int); /// Bbb</p> int test_html_nesting4(int); +// expected-warning@+3 {{HTML tag 'b' requires an end tag}} +// expected-warning@+2 {{HTML tag 'i' requires an end tag}} // expected-warning@+1 {{HTML end tag does not match any start tag}} /// <b><i>Meow</a> int test_html_nesting5(int); @@ -81,6 +91,9 @@ int test_html_nesting6(int); /// <b><i>Meow</b></i> int test_html_nesting7(int); +// expected-warning@+1 {{HTML tag 'b' requires an end tag}} +/// <b>Meow +int test_html_nesting8(int); // expected-warning@+1 {{empty paragraph passed to '\brief' command}} /// \brief\returns Aaa |