From 54211b921c86a4aa69e7390a662a48bf99011de1 Mon Sep 17 00:00:00 2001 From: cvium Date: Sat, 6 Mar 2021 19:07:02 +0100 Subject: [PATCH] rider is a prick --- .../Library/PathExtensions.cs | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/Emby.Server.Implementations/Library/PathExtensions.cs b/Emby.Server.Implementations/Library/PathExtensions.cs index 41e64abf32..d9e20e19ac 100644 --- a/Emby.Server.Implementations/Library/PathExtensions.cs +++ b/Emby.Server.Implementations/Library/PathExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.IO; using System.Text.RegularExpressions; namespace Emby.Server.Implementations.Library @@ -60,19 +61,11 @@ namespace Emby.Server.Implementations.Library /// , or is empty. public static bool TryReplaceSubPath(this string path, string subPath, string newSubPath, [NotNullWhen(true)] out string? newPath) { - if (string.IsNullOrWhiteSpace(path)) - { - throw new ArgumentNullException(nameof(path)); - } - - if (string.IsNullOrWhiteSpace(subPath)) - { - throw new ArgumentNullException(nameof(subPath)); - } + newPath = null; - if (string.IsNullOrWhiteSpace(newSubPath)) + if (path.Length == 0 || subPath.Length == 0 || newSubPath.Length == 0 || subPath.Length > path.Length) { - throw new ArgumentNullException(nameof(newSubPath)); + return false; } char oldDirectorySeparatorChar; @@ -91,15 +84,8 @@ namespace Emby.Server.Implementations.Library newDirectorySeparatorChar = '\\'; } - if (path.Contains(oldDirectorySeparatorChar, StringComparison.Ordinal)) - { - path = path.Replace(oldDirectorySeparatorChar, newDirectorySeparatorChar); - } - - if (subPath.Contains(oldDirectorySeparatorChar, StringComparison.Ordinal)) - { - subPath = subPath.Replace(oldDirectorySeparatorChar, newDirectorySeparatorChar); - } + path = path.Replace(oldDirectorySeparatorChar, newDirectorySeparatorChar); + subPath = subPath.Replace(oldDirectorySeparatorChar, newDirectorySeparatorChar); // We have to ensure that the sub path ends with a directory separator otherwise we'll get weird results // when the sub path matches a similar but in-complete subpath