Fix subpath check

This commit is contained in:
Vic 2023-01-19 16:05:39 +08:00
parent 383298a46b
commit a6b7c5898b

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.Explorer.Exceptions;
using System.IO;
namespace Flow.Launcher.Plugin.Explorer.Search
{
@ -119,7 +120,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}
results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any(
excludedPath => r.SubTitle.StartsWith(excludedPath.Path, StringComparison.OrdinalIgnoreCase)));
excludedPath => IsSubPathOf(r.SubTitle, excludedPath.Path)));
return results.ToList();
}
@ -254,5 +255,16 @@ namespace Flow.Launcher.Plugin.Explorer.Search
&& search != "%%"
&& !search.Contains('\\');
}
// https://stackoverflow.com/a/66877016
internal static bool IsSubPathOf(string subPath, string basePath)
{
var rel = Path.GetRelativePath(basePath, subPath);
return rel != "."
&& rel != ".."
&& !rel.StartsWith("../")
&& !rel.StartsWith(@"..\")
&& !Path.IsPathRooted(rel);
}
}
}