mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 02:59:57 +00:00
Adds rel=noreferrer and rel=noopener to autolinks (Fixes #46)
This commit is contained in:
parent
282f43e8f1
commit
4a5db9e2ad
@ -211,9 +211,19 @@ export default class App {
|
||||
// Prevents input from having injected markup
|
||||
cleanInput(input) {
|
||||
input = input.replace(/\r?\n/g, '<br />');
|
||||
let sanitized = he.encode(input);
|
||||
sanitized = Autolinker.link(sanitized);
|
||||
return sanitized;
|
||||
return this.autolinker(he.encode(input));
|
||||
}
|
||||
|
||||
// Adds rel=noopener noreferrer to autolinked links (Addresses #46 from @Mickael-van-der-Beek)
|
||||
autolinker(sanitized) {
|
||||
return Autolinker.link(sanitized, {
|
||||
replaceFn: function(match) {
|
||||
const tag = match.buildTag();
|
||||
tag.setAttr('rel', 'noopener noreferrer');
|
||||
|
||||
return tag;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sets the client's username
|
||||
|
@ -358,3 +358,9 @@ html.no-touchevents .chat #input-icons {
|
||||
font-style: italic;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.external-link:after {
|
||||
content: 'External Link';
|
||||
color: #FFF;
|
||||
background-color: red;
|
||||
}
|
||||
|
8
src/public/vendor/autolinker.min.js
vendored
8
src/public/vendor/autolinker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -38,10 +38,11 @@ describe('App', () => {
|
||||
app = new App();
|
||||
});
|
||||
|
||||
it('should create HTML links from URLs', () => {
|
||||
it('should create HTML links from URLs with "rel=noopener noreferrer"', () => {
|
||||
let input = app.cleanInput('cnn.com');
|
||||
assert.equal(input, '<a href="http://cnn.com" target="_blank">cnn.com</a>');
|
||||
assert.equal(input, '<a href="http://cnn.com" target="_blank" rel="noopener noreferrer">cnn.com</a>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user