👔 Text sanitizer no longer remove new lines and tabs
This commit is contained in:
parent
f155b4e2ac
commit
eef64df81a
@ -9,15 +9,24 @@ public abstract class TextSanitizer
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text)) return text;
|
if (string.IsNullOrEmpty(text)) return text;
|
||||||
|
|
||||||
|
// List of control characters to preserve
|
||||||
|
var preserveControlChars = new[] { '\n', '\r', '\t', ' ' };
|
||||||
|
|
||||||
var filtered = new StringBuilder();
|
var filtered = new StringBuilder();
|
||||||
foreach (var ch in from ch in text
|
foreach (var ch in text)
|
||||||
let category = CharUnicodeInfo.GetUnicodeCategory(ch)
|
{
|
||||||
where category is not (UnicodeCategory.Control or UnicodeCategory.Format
|
var category = CharUnicodeInfo.GetUnicodeCategory(ch);
|
||||||
or UnicodeCategory.NonSpacingMark)
|
|
||||||
select ch)
|
// Keep whitespace and other specified control characters
|
||||||
|
if (category is not UnicodeCategory.Control || preserveControlChars.Contains(ch))
|
||||||
|
{
|
||||||
|
// Still filter out Format and NonSpacingMark categories
|
||||||
|
if (category is not (UnicodeCategory.Format or UnicodeCategory.NonSpacingMark))
|
||||||
{
|
{
|
||||||
filtered.Append(ch);
|
filtered.Append(ch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return filtered.ToString();
|
return filtered.ToString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user