From 3db9dafaa8297dd3aabc81f97a80796c3c968eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vaillant?= Date: Fri, 12 Jul 2024 13:53:17 +0200 Subject: [PATCH] Added guard against negative index values --- src/Arcus.Testing.Assert/AssertCsv.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Arcus.Testing.Assert/AssertCsv.cs b/src/Arcus.Testing.Assert/AssertCsv.cs index ef7517e0..ae244460 100644 --- a/src/Arcus.Testing.Assert/AssertCsv.cs +++ b/src/Arcus.Testing.Assert/AssertCsv.cs @@ -76,6 +76,11 @@ public AssertCsvOptions IgnoreColumn(string headerName) /// The zero-based index of the column that should be ignored. public AssertCsvOptions IgnoreColumn(int index) { + if (index < 0) + { + throw new ArgumentOutOfRangeException(nameof(index), $"Requires a positive '{nameof(index)}' value when adding an ignored column of a CSV table"); + } + _ignoredColumnIndexes.Add(index); return this; } @@ -392,7 +397,7 @@ private static void EnsureOnlyIgnoreColumnsOnPresentHeaders(CsvTable expected, C $"please provide such headers in the contents, or remove the 'options.{nameof(AssertCsvOptions.IgnoreColumn)}' call(s)") .ToString()); } - + if (options.IgnoredColumnIndexes.Count > 0 && options.ColumnOrder == AssertCsvOrder.Ignore) { throw new EqualAssertionException(