Skip to content

Commit

Permalink
Merge pull request #7379 from RocketChat/fix-flash-of-unescaped-message
Browse files Browse the repository at this point in the history
[FIX] Message being displayed unescaped
  • Loading branch information
rodrigok committed Jul 3, 2017
2 parents 010a60a + 8924b67 commit 2d8aa63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
31 changes: 9 additions & 22 deletions packages/rocketchat-markdown/markdowncode.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,16 @@ class MarkdownCode {

if (codeMatch != null) {
// Process highlight if this part is code
let code;
let lang;
let result;
const singleLine = codeMatch[0].indexOf('\n') === -1;

if (singleLine) {
lang = '';
code = _.unescapeHTML(codeMatch[1] + codeMatch[2]);
} else {
lang = codeMatch[1];
code = _.unescapeHTML(codeMatch[2]);
}

if (s.trim(lang) === '') {
lang = '';
}

if (!Array.from(hljs.listLanguages()).includes(s.trim(lang))) {
result = hljs.highlightAuto((lang + code));
} else {
result = hljs.highlight(s.trim(lang), code);
}

const lang = !singleLine && Array.from(hljs.listLanguages()).includes(s.trim(codeMatch[1])) ? s.trim(codeMatch[1]) : '';
const code =
singleLine ?
_.unescapeHTML(codeMatch[1]) :
lang === '' ?
_.unescapeHTML(codeMatch[1] + codeMatch[2]) :
_.unescapeHTML(codeMatch[2]);

const result = lang === '' ? hljs.highlightAuto((lang + code)) : hljs.highlight(lang, code);
const token = `=!=${ Random.id() }=!=`;

message.tokens.push({
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-mentions/Mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default class {
});
}
replaceChannels(str, message) {
return str.replace(this.channelMentionRegex, (match, name) => {
//since apostrophe escaped contains # we need to unescape it
return str.replace(/'/g, '\'').replace(this.channelMentionRegex, (match, name) => {
if (message.temp == null && _.findWhere(message.channels, {name}) == null) {
return match;
}
Expand Down

0 comments on commit 2d8aa63

Please sign in to comment.