escapeHtml function
Escapes special HTML characters in text content and attribute values to prevent XSS.
Encodes & (&), < (<), > (>), " ("), and ' (').
This function is applied automatically during SSR rendering for all element text nodes,
class names, style strings, and attribute values.
final safe = escapeHtml('<script>alert("xss")</script>');
// Returns: '<script>alert("xss")</script>'
Implementation
String escapeHtml(String input) {
return input
.replaceAll('&', '&')
.replaceAll('<', '<')
.replaceAll('>', '>')
.replaceAll('"', '"')
.replaceAll("'", ''');
}