From a6b7c5898b1a472b3d377f40e2b089b8d5c472b1 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 19 Jan 2023 16:05:39 +0800 Subject: [PATCH] Fix subpath check --- .../Search/SearchManager.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index ce1283e06..4a25fe0ad 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -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); + } } }