From 337e47b84b3456ab402c5b49d6811e7ad2cafc0b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 25 Jul 2023 09:21:20 -0500 Subject: fix crash validating shares --- src/slskd/Core/Options.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index c438c03c..2ee21733 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -652,17 +652,19 @@ namespace slskd { var results = new List(); + var directories = Directories ?? Enumerable.Empty(); + bool IsBlankPath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])$"); - Directories.Where(share => IsBlankPath(share)).ToList() + directories?.Where(share => IsBlankPath(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} doees not specify a path"))); bool IsRootMount(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])/$"); - Directories.Where(share => IsRootMount(share)).ToList() + directories?.Where(share => IsRootMount(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} specifies a root mount, which is not supported."))); // starts with '/', 'X:', or '\\' bool IsAbsolutePath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$"); - Directories.Where(share => !IsAbsolutePath(share)).ToList() + directories?.Where(share => !IsAbsolutePath(share)).ToList() .ForEach(relativePath => results.Add(new ValidationResult($"Share {relativePath} contains a relative path; only absolute paths are supported."))); (string Raw, string Alias, string Path) Digest(string share) @@ -677,7 +679,7 @@ namespace slskd return (share, share.Split(new[] { '/', '\\' }).Last(), share); } - var digestedShared = Directories + var digestedShared = directories .Select(share => Digest(share.TrimEnd('/', '\\'))) .ToHashSet(); -- cgit v1.2.3