validateTextContent function
Validates and sanitizes text content. Returns the validated text string.
Implementation
String validateTextContent(String? text, {bool? enableSecurity}) {
final shouldValidate = enableSecurity ?? TextSecurityConfig.enforceValidation;
if (text == null) return '';
if (!shouldValidate) return text;
if (text.length > TextSecurityConfig.maxTextLength) {
if (TextSecurityConfig.enableSecurityLogging) {
debugPrint(
'[SAC Text Security] Text length ${text.length} exceeds max ${TextSecurityConfig.maxTextLength}',
);
}
return '${text.substring(0, TextSecurityConfig.maxTextLength)}...';
}
return text;
}