Skip to content

Commit

Permalink
Use ordinal instead of invariant/current culture for string compariso…
Browse files Browse the repository at this point in the history
…ns, we should default to using ordinal unless we actually want to deal with culture (#188)

https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1309?view=vs-2019
  • Loading branch information
flin-8 authored Jan 31, 2020
1 parent 5ce2fd0 commit 57e3d6d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ private void FilteredSuggestedTagsOnFilter(object sender, FilterEventArgs filter

if (item.IsCreateEntry)
{
filterEventArgs.Accepted = !string.IsNullOrWhiteSpace(Text) && !SuggestedTags.Contains(Text, StringComparison.InvariantCultureIgnoreCase) && !SelectedTags.Contains(Text, StringComparison.InvariantCultureIgnoreCase);
filterEventArgs.Accepted = !string.IsNullOrWhiteSpace(Text) && !SuggestedTags.Contains(Text, StringComparison.OrdinalIgnoreCase) && !SelectedTags.Contains(Text, StringComparison.OrdinalIgnoreCase);
return;
}

if (SelectedTags.Contains(item.Value, StringComparison.CurrentCultureIgnoreCase))
if (SelectedTags.Contains(item.Value, StringComparison.OrdinalIgnoreCase))
{
filterEventArgs.Accepted = false;
return;
}

if (item.Value.Contains(Text, StringComparison.CurrentCultureIgnoreCase))
if (item.Value.Contains(Text, StringComparison.OrdinalIgnoreCase))
{
filterEventArgs.Accepted = true;
return;
Expand Down Expand Up @@ -251,9 +251,9 @@ private void ExecuteRemoveCommand(string stringValue)

private bool AddTag(string value)
{
if (SelectedTags.Contains(value, StringComparison.CurrentCultureIgnoreCase)) return false;
if (SelectedTags.Contains(value, StringComparison.OrdinalIgnoreCase)) return false;

var matchingSuggested = SuggestedTags.Find(value, StringComparison.CurrentCultureIgnoreCase);
var matchingSuggested = SuggestedTags.Find(value, StringComparison.OrdinalIgnoreCase);

SelectedTags.Add(matchingSuggested ?? value);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void UpdateMachinePolicies()

void UpdateSelection(ObservableCollection<string> selectedCollection, IEnumerable<string> potentialValues)
{
var potentialValuesSet = new HashSet<string>(potentialValues, StringComparer.InvariantCulture);
var potentialValuesSet = new HashSet<string>(potentialValues, StringComparer.Ordinal);
selectedCollection.RemoveWhere(v => !potentialValuesSet.Contains(v));
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/Octopus.Manager.Tentacle/Validators/InstanceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public HashSet<string> ExistingInstanceNames
}

public static readonly DependencyProperty ExistingInstanceNamesProperty = DependencyProperty.Register(
"ExistingInstanceNames", typeof(HashSet<string>), typeof(InstanceNameWrapper), new PropertyMetadata(new HashSet<string>(StringComparer.CurrentCultureIgnoreCase)));
"ExistingInstanceNames", typeof(HashSet<string>), typeof(InstanceNameWrapper), new PropertyMetadata(new HashSet<string>(StringComparer.OrdinalIgnoreCase)));
}
}
19 changes: 0 additions & 19 deletions source/Octopus.Tentacle.Tests/Support/InMemoryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,5 @@ public string GetLog()
{
return logText.ToString();
}

public void AssertContains(LogCategory category, string partialString)
{
var match = GetLog()
.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault(line => line.StartsWith(category.ToString()) &&
CultureInfo.CurrentCulture.CompareInfo.IndexOf(line, partialString, CompareOptions.IgnoreCase) >= 0);

if (match == null) throw new Exception($"The log does not contain any {category} entry containing the substring {partialString}.");
}

public void AssertContains(string partialString)
{
var match = GetLog()
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault(line => CultureInfo.CurrentCulture.CompareInfo.IndexOf(line, partialString, CompareOptions.IgnoreCase) >= 0);

if (match == null) throw new Exception($"The log does not contain any entry containing the substring {partialString}.");
}
}
}

0 comments on commit 57e3d6d

Please sign in to comment.