From 5ac518b02ac95ebf67a16388fe4d1a71ca1a5d83 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 13 May 2024 12:47:35 -0400 Subject: Backport pull request #11570 from jellyfin/release-10.9.z Fix absolute path checking on windows Original-merge: 6689d837d6dcfa0925efdbd9c76a7e1fe4f7cc54 Merged-by: crobibero Backported-by: Joshua M. Boniface --- Emby.Server.Implementations/IO/ManagedFileSystem.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'Emby.Server.Implementations/IO/ManagedFileSystem.cs') diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs index 67854a2a7..d5afac266 100644 --- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs @@ -80,12 +80,14 @@ namespace Emby.Server.Implementations.IO public virtual string MakeAbsolutePath(string folderPath, string filePath) { // path is actually a stream - if (string.IsNullOrWhiteSpace(filePath) || filePath.Contains("://", StringComparison.Ordinal)) + if (string.IsNullOrWhiteSpace(filePath)) { return filePath; } - if (filePath.Length > 3 && filePath[1] == ':' && filePath[2] == '/') + var isAbsolutePath = Path.IsPathRooted(filePath) && (!OperatingSystem.IsWindows() || filePath[0] != '\\'); + + if (isAbsolutePath) { // absolute local path return filePath; @@ -97,17 +99,10 @@ namespace Emby.Server.Implementations.IO return filePath; } - var firstChar = filePath[0]; - if (firstChar == '/') - { - // for this we don't really know - return filePath; - } - var filePathSpan = filePath.AsSpan(); - // relative path - if (firstChar == '\\') + // relative path on windows + if (filePath[0] == '\\') { filePathSpan = filePathSpan.Slice(1); } -- cgit v1.2.3