Special charaacter bug solved

This commit is contained in:
Eudes Inácio
2023-12-01 12:19:20 +01:00
parent c978447eb1
commit d3c551dfbb
5 changed files with 62 additions and 10 deletions
+43 -2
View File
@@ -24,13 +24,54 @@ export class DomSanitizerService {
}
private encodeSpecialCharacters(input: string): string {
const specialCharactersMap: Record<string, string> = {
'!': '&#33;',
'@': '&#64;',
'#': '&#35;',
'$': '&#36;',
'%': '&#37;',
'^': '&#94;',
'&': '&#38;',
'*': '&#42;',
'(': '&#40;',
')': '&#41;',
'-': '&#45;',
'_': '&#95;',
'+': '&#43;',
'=': '&#61;',
'{': '&#123;',
'}': '&#125;',
'|': '&#124;',
'\\': '&#92;',
':': '&#58;',
';': '&#59;',
'"': '&#34;',
"'": '&#39;',
'<': '&#60;',
'>': '&#62;',
',': '&#44;',
'.': '&#46;',
'?': '&#63;',
'/': '&#47;',
'ã': '&atilde;', // ã
'ç': '&ccedil;', // ç
'Â': '&Acirc;', // Â
'â': '&acirc;', // â
'Ã': '&Atilde;', // Ã
};
return input.replace(/[!@#$%^&*()-_+=\{\}|\\:;"'<>,.?/ãçÂâÃ]/g, match => specialCharactersMap[match] || match);
}
// private encodeSpecialCharacters(input: string): string {
// You can use a library like DOMPurify to encode special characters
return DOMPurify.sanitize(input);
// return DOMPurify.sanitize(input);
// If you don't want to use an external library, you can manually encode
// Here's a simple example, you may need to extend this based on your requirements
/* return input.replace(/</g, '&lt;').replace(/>/g, '&gt;'); */
}
// }
/* sanitizeInput(input: string): string {
return this.sanitizer.sanitize(SecurityContext.HTML, input);