Skip to content

Commit db8ba91

Browse files
Fix subpath
1 parent 8bac95d commit db8ba91

File tree

1 file changed

+13
-2
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+13
-2
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,17 @@ public static void Dispose()
737737
}
738738
}
739739

740+
// https://stackoverflow.com/a/66877016
741+
private static bool IsSubPathOf(string subPath, string basePath)
742+
{
743+
var rel = Path.GetRelativePath(basePath, subPath);
744+
return rel != "."
745+
&& rel != ".."
746+
&& !rel.StartsWith("../")
747+
&& !rel.StartsWith(@"..\")
748+
&& !Path.IsPathRooted(rel);
749+
}
750+
740751
private static List<string> GetCommonParents(IEnumerable<ProgramSource> programSources)
741752
{
742753
// To avoid unnecessary io
@@ -748,8 +759,8 @@ private static List<string> GetCommonParents(IEnumerable<ProgramSource> programS
748759
HashSet<ProgramSource> parents = group.ToHashSet();
749760
foreach (var source in group)
750761
{
751-
if (parents.Any(p => source.Location.StartsWith(p.Location, StringComparison.OrdinalIgnoreCase) &&
752-
source != p))
762+
if (parents.Any(p => IsSubPathOf(source.Location, p.Location) &&
763+
source != p)) // TODO startwith not accurate
753764
{
754765
parents.Remove(source);
755766
}

0 commit comments

Comments
 (0)