sanitizeTitleText function
Sanitize title text to prevent overflow and potential issues.
Pass enableSecurity to override global setting, or leave null to use global.
Implementation
String sanitizeTitleText(String? text, {bool? enableSecurity}) {
if (text == null || text.isEmpty) return '';
final shouldValidate =
enableSecurity ?? AppBarSecurityConfig.enforceValidation;
if (!shouldValidate) return text;
var sanitized = text.trim();
if (sanitized.length > AppBarSecurityConfig.maxTitleLength) {
_logAppBarSecurity(
'Title truncated from ${sanitized.length} to ${AppBarSecurityConfig.maxTitleLength}',
);
sanitized =
'${sanitized.substring(0, AppBarSecurityConfig.maxTitleLength - 3)}...';
}
return sanitized;
}