Audit culture bugs (#7707)

* Added comments and fixed CultureInfo /  StringComparison where appropriate

* Addressed comments

* Fixed comment
This commit is contained in:
Avneet Kaur
2020-10-30 16:43:09 -07:00
committed by GitHub
parent bd34127cd4
commit 2c5b9b4d52
54 changed files with 160 additions and 28 deletions

View File

@@ -17,6 +17,8 @@ namespace Microsoft.Plugin.Folder.Sources
private static IEnumerable<string> InitialDriverList()
{
var directorySeparatorChar = System.IO.Path.DirectorySeparatorChar;
// Using InvariantCulture since this is internal
return DriveInfo.GetDrives()
.Select(driver => driver.Name.ToLower(CultureInfo.InvariantCulture).TrimEnd(directorySeparatorChar));
}

View File

@@ -27,6 +27,7 @@ namespace Microsoft.Plugin.Folder.Sources
throw new ArgumentNullException(paramName: nameof(query));
}
// Using OrdinalIgnoreCase since this is internal
return _folderLinks.FolderLinks()
.Where(x => x.Nickname.StartsWith(query, StringComparison.OrdinalIgnoreCase));
}
@@ -38,7 +39,8 @@ namespace Microsoft.Plugin.Folder.Sources
throw new ArgumentNullException(nameof(search));
}
if (search.StartsWith(@"\\", StringComparison.InvariantCulture))
// Using Ordinal this is internal and we're comparing symbols
if (search.StartsWith(@"\\", StringComparison.Ordinal))
{ // share folder
return true;
}
@@ -48,6 +50,7 @@ namespace Microsoft.Plugin.Folder.Sources
if (driverNames.Any())
{
// Using InvariantCultureIgnoreCase since this is searching for drive names
if (driverNames.Any(dn => search.StartsWith(dn, StringComparison.InvariantCultureIgnoreCase)))
{
// normal drive letter

View File

@@ -60,6 +60,7 @@ namespace Microsoft.Plugin.Folder.Sources
}
// Remove everything after the last \ and add *
// Using InvariantCulture since this is internal
incompleteName = search.Substring(index + 1)
.ToLower(CultureInfo.InvariantCulture) + "*";
search = search.Substring(0, index + 1);
@@ -71,7 +72,8 @@ namespace Microsoft.Plugin.Folder.Sources
else
{
// folder exist, add \ at the end of doesn't exist
if (!search.EndsWith(@"\", StringComparison.InvariantCulture))
// Using Ordinal since this is internal and is used for a symbol
if (!search.EndsWith(@"\", StringComparison.Ordinal))
{
search += @"\";
}

View File

@@ -24,6 +24,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
var result = new Wox.Plugin.Result(StringMatcher.FuzzySearch(Search, Path.GetFileName(FilePath)).MatchData)
{
Title = Title,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_file_result_subtitle, FilePath),
IcoPath = FilePath,
Action = c => ShellAction.Execute(FilePath, contextApi),

View File

@@ -37,6 +37,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
Title = Title,
IcoPath = Path,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
QueryTextDisplay = Path,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path },

View File

@@ -23,6 +23,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
Title = Properties.Resources.Microsoft_plugin_folder_truncation_warning_title,
QueryTextDisplay = Search,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.Microsoft_plugin_folder_truncation_warning_subtitle, PostTruncationCount, PreTruncationCount),
IcoPath = WarningIconPath,
};

View File

@@ -39,7 +39,8 @@ namespace Microsoft.Plugin.Folder.Sources
var sanitizedPath = Regex.Replace(search, @"[\/\\]+", "\\");
// A network path must start with \\
if (!sanitizedPath.StartsWith("\\", StringComparison.InvariantCulture))
// Using Ordinal since this is internal and used with a symbol
if (!sanitizedPath.StartsWith("\\", StringComparison.Ordinal))
{
return sanitizedPath;
}

View File

@@ -28,6 +28,8 @@ namespace Microsoft.Plugin.Folder
{
Title = Title,
IcoPath = Path,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
QueryTextDisplay = Path,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path },