From e8426c1fcdd69f580fb86fab911511f2db292470 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 9 Aug 2021 19:49:44 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 2 +- source/Plugins/AyaNova.Plugin.V8/util.cs | 29 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 4be2194..abb5b9e 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -163,7 +163,7 @@ namespace AyaNova.PlugIn.V8 return; } ExportAssignedDocs = dOpt.ExportAssignedDocs; - ImportTag = dOpt.Tags; + ImportTag = Util.NormalizeTag(dOpt.Tags); //here because we logged in fine and can proceed //MessageBox.Show("Login successful! JWT is " + util.JWT); diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index 0bc3207..8f0b819 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -120,9 +120,9 @@ namespace AyaNova.PlugIn.V8 return false; } - a = await GetAsync("server-state/"); - ServerState = a.ObjectResponse["data"]["serverState"].Value(); - + a = await GetAsync("server-state/"); + ServerState = a.ObjectResponse["data"]["serverState"].Value(); + return true; } @@ -132,7 +132,7 @@ namespace AyaNova.PlugIn.V8 } - + @@ -315,10 +315,12 @@ namespace AyaNova.PlugIn.V8 return Convert.ToBase64String(b); } + public static string NormalizeTag(string inObj) { + if (string.IsNullOrWhiteSpace(inObj)) return null; //Must be lowercase per rules - //This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode + //This may be naive when we get international cust omers but for now supporting utf-8 and it appears it's safe to do this with unicode inObj = inObj.ToLowerInvariant(); //No spaces in tags, replace with dashes inObj = inObj.Replace(" ", "-"); @@ -327,10 +329,25 @@ namespace AyaNova.PlugIn.V8 //Ensure doesn't start or end with a dash inObj = inObj.Trim('-'); //No longer than 255 characters - inObj = MaxLength(inObj, 255); + inObj = StringUtil.MaxLength(inObj, 255); return inObj; } + //clean up tags from client submission + //remove dupes, substitute dashes for spaces, lowercase and shorten if exceed 255 chars + //and sorts before returning to ensure consistent ordering + public static List NormalizeTags(List inTags) + { + if (inTags == null || inTags.Count == 0) return inTags; + + List outTags = new List(); + foreach (var tag in inTags) + outTags.Add(NormalizeTag(tag)); + outTags.Sort(); + return outTags.Distinct().ToList(); + } + + /// /// Trim a string if necessary ///