Skip to content

Commit 87bd7cf

Browse files
committed
Made getting the comment text more robust.
Especially call EscapeHtml() in case we unexpectedly failed to receive the renderedText, since we do not really know the content of `text` then.
1 parent d4be3fd commit 87bd7cf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Comments.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
import { gWorkItemRESTClient } from './Globals';
8-
import { DiffHtmlText } from './Utils';
8+
import { DiffHtmlText, EscapeHtml } from './Utils';
99
import { CommentFormat } from 'azure-devops-extension-api/Comments';
1010

1111

@@ -174,13 +174,20 @@ function GetHtmlFromComment(comment, commentOrUpdate)
174174
// - format == markdown: GetCommentsRESTRequest(), `text`
175175
// GetCommentsVersionsRESTRequest(): Never (`text` contains ACK)
176176
//
177-
if (comment.format === undefined || comment.format === CommentFormat.Html || commentOrUpdate.renderedText === undefined) {
178-
return commentOrUpdate.text; // For html, do NOT use renderedText! See above!
177+
if (comment.format === undefined || comment.format === CommentFormat.Html) {
178+
// If `format` is undefined, we have an old ADO version, implying html.
179+
// Moreover, the correct html is in `text`, not in `renderedText`. See above.
180+
return commentOrUpdate.text;
179181
}
180-
else {
181-
// Probably a markdown comment, at least now (might have been html in earlier versions of the comment).
182+
else if (commentOrUpdate.renderedText !== undefined) {
183+
// Probably a markdown comment, at least in the latest comment version (might have been html in earlier
184+
// versions of the comment, in which case `renderedText` is also fine; compare explanation above).
182185
return commentOrUpdate.renderedText;
183186
}
187+
else {
188+
// We shouldn't be able to reach this code here.
189+
return EscapeHtml(commentOrUpdate.text);
190+
}
184191
}
185192

186193

0 commit comments

Comments
 (0)