Merge pull request #2332 from VictoriousRaptor/fix-exclude-path-check

Fix exclude path check for index search
This commit is contained in:
VictoriousRaptor 2023-09-11 19:23:57 +08:00 committed by GitHub
commit ef84b2b597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View file

@ -263,7 +263,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
} }
/// <summary> /// <summary>
/// Returns if <paramref name="parentPath"/> contains <paramref name="subPath"/>. /// Returns if <paramref name="parentPath"/> contains <paramref name="subPath"/>. Equal paths are not considered to be contained by default.
/// From https://stackoverflow.com/a/66877016 /// From https://stackoverflow.com/a/66877016
/// </summary> /// </summary>
/// <param name="parentPath">Parent path</param> /// <param name="parentPath">Parent path</param>

View file

@ -1,4 +1,4 @@
using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Plugin.SharedCommands;
using NUnit.Framework; using NUnit.Framework;
namespace Flow.Launcher.Test namespace Flow.Launcher.Test
@ -33,21 +33,21 @@ namespace Flow.Launcher.Test
[TestCase(@"c:\foo", @"c:\foo\..\bar\baz", false)] [TestCase(@"c:\foo", @"c:\foo\..\bar\baz", false)]
[TestCase(@"c:\bar", @"c:\foo\..\bar\baz", true)] [TestCase(@"c:\bar", @"c:\foo\..\bar\baz", true)]
[TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)] [TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)]
// Equality
[TestCase(@"c:\foo", @"c:\foo", false)]
[TestCase(@"c:\foo\", @"c:\foo", false)]
[TestCase(@"c:\foo", @"c:\foo\", false)]
public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult) public void GivenTwoPaths_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
{ {
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path)); Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path));
} }
// Equality
[TestCase(@"c:\foo", @"c:\foo", false)]
[TestCase(@"c:\foo\", @"c:\foo", false)]
[TestCase(@"c:\foo", @"c:\foo\", false)]
[TestCase(@"c:\foo", @"c:\foo", true)] [TestCase(@"c:\foo", @"c:\foo", true)]
[TestCase(@"c:\foo\", @"c:\foo", true)] [TestCase(@"c:\foo\", @"c:\foo", true)]
[TestCase(@"c:\foo", @"c:\foo\", true)] [TestCase(@"c:\foo", @"c:\foo\", true)]
public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeTrue(string parentPath, string path, bool expectedResult) public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeExpectedResult(string parentPath, string path, bool expectedResult)
{ {
Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, true)); Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult));
} }
} }
} }

View file

@ -123,7 +123,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
} }
results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any( results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any(
excludedPath => FilesFolders.PathContains(excludedPath.Path, r.SubTitle))); excludedPath => FilesFolders.PathContains(excludedPath.Path, r.SubTitle, allowEqual: true)));
return results.ToList(); return results.ToList();
} }