Skip to content

Commit efe1e2f

Browse files
committed
Sort the results of Get-SecretInfo correctly
Instead of using a `SortedDictionary` which introduced a bug because it required the keys (secret names) to be unique, we just sort the array directly using a comparer that sorts by name. Fixes #95.
1 parent bc00e0d commit efe1e2f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/code/SecretManagement.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,15 +1092,9 @@ private void WriteResults(SecretInformation[] results)
10921092
if (results == null) { return; }
10931093

10941094
// Ensure each vaults results are sorted by secret name.
1095-
var sortedList = new SortedDictionary<string, SecretInformation>(StringComparer.OrdinalIgnoreCase);
1096-
foreach (var item in results)
1097-
{
1098-
sortedList.Add(
1099-
key: item.Name,
1100-
value: item);
1101-
}
1095+
Array.Sort(results, new SecretInformationComparer());
11021096

1103-
foreach (var item in sortedList.Values)
1097+
foreach (var item in results)
11041098
{
11051099
WriteObject(item);
11061100
}

src/code/Utils.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ private SecretInformation()
324324

325325
#endregion
326326
}
327+
328+
/// <summary>
329+
/// Compares secret information by name.
330+
/// </summary>
331+
public class SecretInformationComparer : IComparer<SecretInformation>
332+
{
333+
public int Compare(SecretInformation x, SecretInformation y)
334+
{
335+
return string.Compare(x.Name, y.Name, StringComparison.Ordinal);
336+
}
337+
}
327338

328339
#endregion
329340

0 commit comments

Comments
 (0)