- Prevent null string from being parsed

- cursor pos adjustment through preview
This commit is contained in:
Infi
2024-05-19 16:33:53 +02:00
parent adacf63bc3
commit 51db04a5f5
3 changed files with 161 additions and 21 deletions
+12 -2
View File
@@ -50,7 +50,7 @@ internal static class ChunkUtil
glow.Pop();
break;
case PayloadType.AutoTranslateText:
chunks.Add(new IconChunk(source, link, BitmapFontIcon.AutoTranslateBegin));
chunks.Add(new IconChunk(source, payload, BitmapFontIcon.AutoTranslateBegin));
var autoText = ((AutoTranslatePayload) payload).Text;
Append(autoText.Substring(2, autoText.Length - 4));
chunks.Add(new IconChunk(source, link, BitmapFontIcon.AutoTranslateEnd));
@@ -121,7 +121,17 @@ internal static class ChunkUtil
break;
default:
if (payload is ITextProvider textProvider)
Append(textProvider.Text);
{
// We don't want to parse any null string
var str = textProvider.Text;
var nulIndex = str.IndexOf('\0');
if (nulIndex > 0)
str = str[..nulIndex];
if (string.IsNullOrEmpty(str))
break;
Append(str);
}
break;
}
}