Skip to content

Commit

Permalink
Merge pull request #7644 from jangmarker/ref-to-rel-fix
Browse files Browse the repository at this point in the history
[FIX] Markdown noopener/noreferrer: use correct HTML attribute
  • Loading branch information
rodrigok authored Aug 8, 2017
2 parents 98d3316 + cc5d445 commit 889d742
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/rocketchat-markdown/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MarkdownClass {
// Support ![alt text](http://image url)
msg = msg.replace(new RegExp(`!\\[([^\\]]+)\\]\\(((?:${ schemes }):\\/\\/[^\\)]+)\\)`, 'gm'), function(match, title, url) {
const target = url.indexOf(Meteor.absoluteUrl()) === 0 ? '' : '_blank';
const html = `<a href="${ _.escapeHTML(url) }" title="${ _.escapeHTML(title) }" target="${ _.escapeHTML(target) }" ref="noopener noreferrer"><div class="inline-image" style="background-image: url(${ _.escapeHTML(url) });"></div></a>`;
const html = `<a href="${ _.escapeHTML(url) }" title="${ _.escapeHTML(title) }" target="${ _.escapeHTML(target) }" rel="noopener noreferrer"><div class="inline-image" style="background-image: url(${ _.escapeHTML(url) });"></div></a>`;

if (message && message.tokens) {
const token = `=!=${ Random.id() }=!=`;
Expand All @@ -76,13 +76,13 @@ class MarkdownClass {
// Support [Text](http://link)
msg = msg.replace(new RegExp(`\\[([^\\]]+)\\]\\(((?:${ schemes }):\\/\\/[^\\)]+)\\)`, 'gm'), function(match, title, url) {
const target = url.indexOf(Meteor.absoluteUrl()) === 0 ? '' : '_blank';
return `<a href="${ _.escapeHTML(url) }" target="${ _.escapeHTML(target) }" ref="noopener noreferrer">${ _.escapeHTML(title) }</a>`;
return `<a href="${ _.escapeHTML(url) }" target="${ _.escapeHTML(target) }" rel="noopener noreferrer">${ _.escapeHTML(title) }</a>`;
});

// Support <http://link|Text>
msg = msg.replace(new RegExp(`(?:<|&lt;)((?:${ schemes }):\\/\\/[^\\|]+)\\|(.+?)(?=>|&gt;)(?:>|&gt;)`, 'gm'), (match, url, title) => {
const target = url.indexOf(Meteor.absoluteUrl()) === 0 ? '' : '_blank';
return `<a href="${ _.escapeHTML(url) }" target="${ _.escapeHTML(target) }" ref="noopener noreferrer">${ _.escapeHTML(title) }</a>`;
return `<a href="${ _.escapeHTML(url) }" target="${ _.escapeHTML(target) }" rel="noopener noreferrer">${ _.escapeHTML(title) }</a>`;
});

if (typeof window !== 'undefined' && window !== null ? window.rocketDebug : undefined) { console.log('Markdown', msg); }
Expand Down

0 comments on commit 889d742

Please sign in to comment.