-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[MM-37074] Encapsulate inserted GIFs in inline image markdown #8362
Conversation
Hello @Roy-Orbison, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. |
Adding myself to check the CodeQL alert created on this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check somehow aware of Markdown syntax, thus expecting the .replace()
to also escape possible \
in title
properties? Or is it balking at the escaped [
in the regex? Or incorrectly parsing the escaped \
in the replacement string?
@Roy-Orbison the alert did not consider the Markdown syntax and hence it's a false positive. The changes LGTM and I have dismissed the alert. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @Roy-Orbison! Good catch on the followup to that ticket since it doesn't look like one was created to actually track this separately
@@ -59,7 +59,7 @@ export default class GifPicker extends React.PureComponent { | |||
} | |||
|
|||
handleItemClick = (gif) => { | |||
this.props.onGifClick(gif.max5mbGif); | |||
this.props.onGifClick('![' + gif.title.replace(/]|\[/g, '\\$&') + '](' + gif.max5mbGif + ')'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also good call escaping the square brackets in the gif title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't escape \
characters a well, but that's because the flavour of markdown in MM simply looks for a \
preceding a square bracket. So [\\[x\]](#y)
renders like this on GH [\x], but the first [\
of that rendering is included in the link text on MM.
Markdown is a little ill-defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do plan on switching MM's Markdown to CommonMark which should match GitHub more closely, so we'll likely have to start doing that eventually, but I don't think it's a concern for now. The only way I see this becoming a concern is if Gfycat starts sending us bad data anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All user data is bad data ;)
I tested on that build instance, and the gif markdown worked in all three contexts that receive the updated function parameter (create post, edit post, create comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Roy-Orbison
Tested, looks good to merge.
- Verified GIF inline markdown
Test server destroyed |
Summary
Changes Markdown inserted by GIF picker from
https://thumbs.gfycat.com/LikableValidAlpineroadguidetigerbeetle-size_restricted.gif
to
Ticket Link
As per Other notes of [MM-12290]
https://mattermost.atlassian.net/browse/MM-37074
Screenshots
Release Note