Skip to content

Commit 654462c

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 47bc3b7 commit 654462c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/code/SecretManagement.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1061,15 +1061,9 @@ private void WriteResults(SecretInformation[] results)
10611061
if (results == null) { return; }
10621062

10631063
// Ensure each vaults results are sorted by secret name.
1064-
var sortedList = new SortedDictionary<string, SecretInformation>(StringComparer.OrdinalIgnoreCase);
1065-
foreach (var item in results)
1066-
{
1067-
sortedList.Add(
1068-
key: item.Name,
1069-
value: item);
1070-
}
1064+
Array.Sort(results, new SecretInformationComparer());
10711065

1072-
foreach (var item in sortedList.Values)
1066+
foreach (var item in results)
10731067
{
10741068
WriteObject(item);
10751069
}

src/code/Utils.cs

+11
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ private SecretInformation()
291291

292292
#endregion
293293
}
294+
295+
/// <summary>
296+
/// Compares secret information by name.
297+
/// </summary>
298+
public class SecretInformationComparer : IComparer<SecretInformation>
299+
{
300+
public int Compare(SecretInformation x, SecretInformation y)
301+
{
302+
return string.Compare(x.Name, y.Name, StringComparison.Ordinal);
303+
}
304+
}
294305

295306
#endregion
296307

0 commit comments

Comments
 (0)