From 8fd6b526f851afabd9809c07ce0bcf86dc2bbf70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Thu, 3 Nov 2022 21:59:40 +0100 Subject: [PATCH] Fix indexofoutrange when Path is only ~ --- src/Alma.App/Command/Link/LinkCommand.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Alma.App/Command/Link/LinkCommand.cs b/src/Alma.App/Command/Link/LinkCommand.cs index 6422471..2864f44 100644 --- a/src/Alma.App/Command/Link/LinkCommand.cs +++ b/src/Alma.App/Command/Link/LinkCommand.cs @@ -191,7 +191,8 @@ public class LinkCommand : ICommand { if (path.StartsWith("~")) { - path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path.Substring(2)); + var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + path = path.Length > 1 ? Path.Combine(userProfile, path[2..]) : userProfile; } //TODO: more special character @@ -199,5 +200,5 @@ public class LinkCommand : ICommand return Path.Combine(currentDirectory, path); } - private static string GetRelativePath(string full, string parent) => full.Substring(parent.Length).TrimStart(Path.DirectorySeparatorChar); + private static string GetRelativePath(string full, string parent) => full[parent.Length..].TrimStart(Path.DirectorySeparatorChar); } \ No newline at end of file