sanitizeButtonText function
Sanitize text input to prevent potential issues.
Implementation
String sanitizeButtonText(
String? text, {
int maxLength = 500,
bool? enableSecurity,
}) {
if (text == null) return '';
final shouldValidate =
enableSecurity ?? ButtonSecurityConfig.enforceValidation;
if (!shouldValidate) return text;
// Trim whitespace
var sanitized = text.trim();
// Limit length to prevent UI overflow attacks
if (sanitized.length > maxLength) {
_logSecurity(
'Button text truncated from ${sanitized.length} to $maxLength',
);
sanitized = '${sanitized.substring(0, maxLength - 3)}...';
}
return sanitized;
}