| 1 | /** | 
| 2 | * Codifica un texto para que cambie los caracteres | 
| 3 | * especiales y no se pueda interpretar como | 
| 4 | * etiiqueta HTML. Esta técnica evita la inyección | 
| 5 | * de código. | 
| 6 | * @param { string } texto | 
| 7 | */ | 
| 8 | export function htmlentities(texto) { | 
| 9 | return texto.replace(/[<>"']/g, textoDetectado => { | 
| 10 | switch (textoDetectado) { | 
| 11 | case "<": return "<" | 
| 12 | case ">": return ">" | 
| 13 | case '"': return """ | 
| 14 | case "'": return "'" | 
| 15 | default: return textoDetectado | 
| 16 | } | 
| 17 | }) | 
| 18 | } | 
| 19 |