Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/github/prComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ export class TemporaryComment extends CommentBase {
}

const SUGGESTION_EXPRESSION = /```suggestion(\u0020*(\r\n|\n))((?<suggestion>[\s\S]*?)(\r\n|\n))?```/;
const IMG_EXPRESSION = /<img .*src=['"](?<src>.+?)['"].*?>/g;
const IMG_EXPRESSION = /<img\b[^>]*?\ssrc\s*=\s*['"](?<src>[^'"]+?)['"][^>]*?>/gi;
const IMG_ALT_EXPRESSION = /\salt\s*=\s*(['"])(?<alt>[\s\S]*?)\1/i;
const UUID_EXPRESSION = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/;
export const COMMIT_SHA_EXPRESSION = /(?<![`\/\w])([0-9a-f]{7})([0-9a-f]{33})?(?![`\/\w])/g;

Expand Down Expand Up @@ -352,8 +353,11 @@ export class GHPRComment extends CommentBase {
}

private replaceImg(body: string) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good place for a unit test

return body.replace(IMG_EXPRESSION, (_substring, _1, _2, _3, { src }) => {
return `![image](${src})`;
return body.replace(IMG_EXPRESSION, (substring, _1, _2, _3, { src }) => {
Comment thread
alexr00 marked this conversation as resolved.
const altMatch = substring.match(IMG_ALT_EXPRESSION);
const alt = (altMatch?.groups?.alt ?? '').replace(/[\r\n]+/g, ' ').trim();
const safeAlt = alt.replace(/([\\\[\]`])/g, '\\$1');
return `![${safeAlt || 'image'}](${src})`;
Comment thread
alexr00 marked this conversation as resolved.
});
Comment thread
alexr00 marked this conversation as resolved.
Comment thread
alexr00 marked this conversation as resolved.
}

Expand Down