diff options
| author | cvium <clausvium@gmail.com> | 2021-03-07 22:49:31 +0100 |
|---|---|---|
| committer | cvium <clausvium@gmail.com> | 2021-03-07 22:49:31 +0100 |
| commit | e0db17a9354ff511c31c7bcf02c41d868ed91c5a (patch) | |
| tree | b37ba109335efef56e9001f9799ef278e276c207 /Emby.Naming/Video/CleanStringParser.cs | |
| parent | 8615847a8aba1f504b184e79907e6885215ffdaa (diff) | |
do not throw ArgumentNullException in TryCleanString
Diffstat (limited to 'Emby.Naming/Video/CleanStringParser.cs')
| -rw-r--r-- | Emby.Naming/Video/CleanStringParser.cs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Emby.Naming/Video/CleanStringParser.cs b/Emby.Naming/Video/CleanStringParser.cs index 09a0cd189..deeea4dda 100644 --- a/Emby.Naming/Video/CleanStringParser.cs +++ b/Emby.Naming/Video/CleanStringParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; namespace Emby.Naming.Video @@ -16,7 +17,7 @@ namespace Emby.Naming.Video /// <param name="expressions">List of regex to parse name and year from.</param> /// <param name="newName">Parsing result string.</param> /// <returns>True if parsing was successful.</returns> - public static bool TryClean(string name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName) + public static bool TryClean(string name, IReadOnlyList<Regex> expressions, [NotNullWhen(true)] out ReadOnlySpan<char> newName) { var len = expressions.Count; for (int i = 0; i < len; i++) @@ -31,8 +32,14 @@ namespace Emby.Naming.Video return false; } - private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName) + private static bool TryClean(string name, Regex expression, [NotNullWhen(true)] out ReadOnlySpan<char> newName) { + if (string.IsNullOrEmpty(name)) + { + newName = null; + return false; + } + var match = expression.Match(name); int index = match.Index; if (match.Success && index != 0) |
