[PATCH] D132932: [Clang][Comments] Parse `<img src=""/>` in doc comments correctly

Egor Zhdan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 05:03:58 PDT 2022


egorzhdan created this revision.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a valid HTML5 tag. Previously it triggered a Clang error (`HTML start tag prematurely ended, expected attribute name or '>'`) since Clang was treating `/>` as a text token. This was happening because after lexing the closing quote (`"`) the lexer state was reset to "Normal" while the tag was not actually closed yet: `>` was not yet parsed at that point.

rdar://91464292


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Sema/warn-documentation.cpp


Index: clang/test/Sema/warn-documentation.cpp
===================================================================
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// <br></br>
 int test_html11(int);
 
+/// Aaa bbb<img/>
+int test_html_img1(int);
+
+/// Aaa bbb<img />
+int test_html_img2(int);
+
+/// Aaa bbb<img src="">
+int test_html_img3(int);
+
+/// Aaa bbb<img src=""/>
+int test_html_img3(int);
+
+/// Aaa bbb<img src="" />
+int test_html_img4(int);
+
 /// <blockquote>Meow</blockquote>
 int test_html_nesting1(int);
 
Index: clang/lib/AST/CommentLexer.cpp
===================================================================
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = *BufferPtr;
   if (!isHTMLIdentifierStartingCharacter(C) &&
-      C != '=' && C != '\"' && C != '\'' && C != '>') {
+      C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
     State = LS_Normal;
     return;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132932.456621.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220830/548945e5/attachment-0001.bin>


More information about the cfe-commits mailing list