From ea2f9ef16f713a8154a6c4de6f4a765eae29fbd1 Mon Sep 17 00:00:00 2001 From: cb-tomsearle <42167835+cb-tomsearle@users.noreply.github.com> Date: Tue, 4 May 2021 11:50:26 +0100 Subject: [PATCH] Avoid infinite loop in code generation If a generated code contains a "bad word" it will never escape the generation loop. This patch clears out bad codes so a clean one can be created. --- src/Powells.CouponCode/CouponCodeBuilder.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Powells.CouponCode/CouponCodeBuilder.cs b/src/Powells.CouponCode/CouponCodeBuilder.cs index 8c63f19..eac7342 100644 --- a/src/Powells.CouponCode/CouponCodeBuilder.cs +++ b/src/Powells.CouponCode/CouponCodeBuilder.cs @@ -137,7 +137,7 @@ public CouponCodeBuilder() /// public string Generate(Options opts) { - var parts = new List(); + List parts; // populate the bad words list with this delegate if it was set; if (this.SetBadWordsList != null) @@ -158,6 +158,8 @@ public string Generate(Options opts) // generate parts and combine do { + parts = new List(); + for (var i = 0; i < opts.Parts; i++) { var sb = new StringBuilder();