From 9d601f8e9bed64927ac5cdad5ecac9730d55c435 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 19 May 2025 08:40:18 +0800 Subject: Terminate at null char for audio tags (#14100) --- src/Jellyfin.Extensions/StringExtensions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs index 715cbf220..60df47113 100644 --- a/src/Jellyfin.Extensions/StringExtensions.cs +++ b/src/Jellyfin.Extensions/StringExtensions.cs @@ -135,5 +135,18 @@ namespace Jellyfin.Extensions { return values.Select(i => (i ?? string.Empty).Trim()); } + + /// + /// Truncates a string at the first null character ('\0'). + /// + /// The input string. + /// + /// The substring up to (but not including) the first null character, + /// or the original string if no null character is present. + /// + public static string TruncateAtNull(this string text) + { + return string.IsNullOrEmpty(text) ? text : text.AsSpan().LeftPart('\0').ToString(); + } } } -- cgit v1.2.3