mirror of
https://github.com/NicolasConstant/sengi
synced 2025-02-08 16:08:40 +01:00
Encode html in CW, fix #348
This commit is contained in:
parent
1b7853ec4d
commit
4babd219b4
@ -150,7 +150,8 @@
|
||||
min-height: 80px;
|
||||
display: block;
|
||||
margin: 0 10px 0 $avatar-column-space;
|
||||
padding: 3px 5px 12px 5px;
|
||||
padding: 3px 5px 14px 5px;
|
||||
overflow-wrap: break-word;
|
||||
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
|
@ -100,54 +100,20 @@ export class StatusComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
// private checkContentWarning(status: Status) {
|
||||
// let cwPolicy = this.toolsService.getSettings().contentWarningPolicy;
|
||||
|
||||
// let splittedContent = [];
|
||||
// if ((cwPolicy.policy === ContentWarningPolicyEnum.HideAll && cwPolicy.addCwOnContent.length > 0)
|
||||
// || (cwPolicy.policy === ContentWarningPolicyEnum.AddOnAllContent && cwPolicy.removeCwOnContent.length > 0)
|
||||
// || (cwPolicy.hideCompletlyContent && cwPolicy.hideCompletlyContent.length > 0)) {
|
||||
// let parser = new DOMParser();
|
||||
// let dom = parser.parseFromString((status.content + ' ' + status.spoiler_text).replace("<br/>", " ").replace("<br>", " ").replace(/\n/g, ' '), 'text/html')
|
||||
// let contentToParse = dom.body.textContent;
|
||||
// splittedContent = contentToParse.toLowerCase().split(' ');
|
||||
// }
|
||||
|
||||
// if (cwPolicy.policy === ContentWarningPolicyEnum.None && (status.sensitive || status.spoiler_text)) {
|
||||
// this.setContentWarning(status);
|
||||
// } else if (cwPolicy.policy === ContentWarningPolicyEnum.HideAll) {
|
||||
// let detected = cwPolicy.addCwOnContent.filter(x => splittedContent.find(y => y == x || y == `#${x}`));
|
||||
// if (!detected || detected.length === 0) {
|
||||
// this.status.sensitive = false;
|
||||
// } else {
|
||||
// if (!status.spoiler_text) {
|
||||
// status.spoiler_text = detected.join(' ');
|
||||
// }
|
||||
// this.setContentWarning(status);
|
||||
// }
|
||||
// } else if (cwPolicy.policy === ContentWarningPolicyEnum.AddOnAllContent) {
|
||||
// let detected = cwPolicy.removeCwOnContent.filter(x => splittedContent.find(y => y == x || y == `#${x}`));
|
||||
|
||||
// if (detected && detected.length > 0) {
|
||||
// this.status.sensitive = false;
|
||||
// } else {
|
||||
// this.setContentWarning(status);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (cwPolicy.hideCompletlyContent && cwPolicy.hideCompletlyContent.length > 0) {
|
||||
// let detected = cwPolicy.hideCompletlyContent.filter(x => splittedContent.find(y => y == x || y == `#${x}`));
|
||||
// if (detected && detected.length > 0) {
|
||||
// this.hideStatus = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
private setContentWarning(status: StatusWrapper) {
|
||||
this.hideStatus = status.hide;
|
||||
this.isContentWarned = status.applyCw;
|
||||
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.status.spoiler_text, EmojiTypeEnum.medium);
|
||||
|
||||
let spoiler = this.htmlEncode(status.status.spoiler_text);
|
||||
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, spoiler, EmojiTypeEnum.medium);
|
||||
}
|
||||
|
||||
private htmlEncode(str: string): string {
|
||||
var encodedStr = str.replace(/[\u00A0-\u9999<>\&]/gim, function (i) {
|
||||
return '&#' + i.charCodeAt(0) + ';';
|
||||
});
|
||||
return encodedStr;
|
||||
}
|
||||
|
||||
removeContentWarning(): boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user