diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index d5bd4ce9..eb29999e 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -106,9 +106,9 @@ namespace AyaNova.Biz bool NotUnique = true; long l = 1; do - { + { newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255); - NotUnique = await ct.Widget.AnyAsync(m => m.Name == newUniqueName); + NotUnique = await ct.Widget.AnyAsync(m => m.Name == newUniqueName); } while (NotUnique); outObj.Name = newUniqueName; diff --git a/server/AyaNova/util/StringUtil.cs b/server/AyaNova/util/StringUtil.cs index 814a7ec6..06ad3614 100644 --- a/server/AyaNova/util/StringUtil.cs +++ b/server/AyaNova/util/StringUtil.cs @@ -119,6 +119,11 @@ namespace AyaNova.Util //Used to ensure a unique name generated by appending -nnn is within length requirements by splitting and chopping part of text to keep name public static string UniqueNameBuilder(string oldName, long appendValue, int maxLength) { + //deadman switch + if (appendValue > int.MaxValue) + { + throw new System.OverflowException($"UniqueNameBuilder: Unique name could not be generated for item \"{oldName}\" after {int.MaxValue.ToString()} attempts"); + } var appendString = "-" + appendValue.ToString(); string ret = oldName + appendString; var diff = maxLength - ret.Length;