sanitizen status's links, fix #290
This commit is contained in:
parent
164bf22484
commit
8000f51aaa
|
@ -169,4 +169,11 @@ describe('DatabindedTextComponent', () => {
|
|||
component.text = sample;
|
||||
expect(component.processedText).toContain('Bla<br /><br /><a href class="link-httpslink" title="open link">https://link/</a>');
|
||||
});
|
||||
|
||||
it('should sanitize link', () => {
|
||||
const sample = `https://domain.fr/public.php?op=rss&id=-2&key=60c63a21c2928546b4485017876fe850c6ebcebd#tag:domain.fr,2020-05-26:/49902061`;
|
||||
|
||||
let result = (<any>component).sanitizeLink(sample);
|
||||
expect(result).toBe('https://domain.fr/public.php?op=rss&id=-2&key=60c63a21c2928546b4485017876fe850c6ebcebd#tag:domain.fr,2020-05-26:/49902061');
|
||||
});
|
||||
});
|
|
@ -210,12 +210,14 @@ export class DatabindedTextComponent implements OnInit {
|
|||
let classname = this.getClassNameForLink(link);
|
||||
let els = this.contentElement.nativeElement.querySelectorAll(`.${classname}`);
|
||||
|
||||
let sanitizedLink = this.sanitizeLink(link);
|
||||
|
||||
for (const el of els) {
|
||||
this.renderer.listen(el, 'click', (event) => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
window.open(link, '_blank');
|
||||
window.open(sanitizedLink, '_blank');
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -224,7 +226,7 @@ export class DatabindedTextComponent implements OnInit {
|
|||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
window.open(link, '_blank');
|
||||
window.open(sanitizedLink, '_blank');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -232,6 +234,11 @@ export class DatabindedTextComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
private sanitizeLink(link: string): string {
|
||||
let res = link.replace(/&/g, '&');
|
||||
return res;
|
||||
}
|
||||
|
||||
private getClassNameForHastag(value: string): string {
|
||||
let res = value.replace(/[.,\/#?!@$%+\^&\*;:{}=\-_`~()]/g, "");
|
||||
return `hashtag-${res}`;
|
||||
|
|
Loading…
Reference in New Issue