Skip to content

Commit a6b7c58

Browse files
Fix subpath check
1 parent 383298a commit a6b7c58

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Flow.Launcher.Plugin.Explorer.Exceptions;
11+
using System.IO;
1112

1213
namespace Flow.Launcher.Plugin.Explorer.Search
1314
{
@@ -119,7 +120,7 @@ when ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword)
119120
}
120121

121122
results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any(
122-
excludedPath => r.SubTitle.StartsWith(excludedPath.Path, StringComparison.OrdinalIgnoreCase)));
123+
excludedPath => IsSubPathOf(r.SubTitle, excludedPath.Path)));
123124

124125
return results.ToList();
125126
}
@@ -254,5 +255,16 @@ internal static bool IsEnvironmentVariableSearch(string search)
254255
&& search != "%%"
255256
&& !search.Contains('\\');
256257
}
258+
259+
// https://stackoverflow.com/a/66877016
260+
internal static bool IsSubPathOf(string subPath, string basePath)
261+
{
262+
var rel = Path.GetRelativePath(basePath, subPath);
263+
return rel != "."
264+
&& rel != ".."
265+
&& !rel.StartsWith("../")
266+
&& !rel.StartsWith(@"..\")
267+
&& !Path.IsPathRooted(rel);
268+
}
257269
}
258270
}

0 commit comments

Comments
 (0)