From 37662fabe519d23d5566720a94739d857b5dd3a4 Mon Sep 17 00:00:00 2001 From: dabico Date: Tue, 26 Mar 2024 10:54:56 +0100 Subject: [PATCH] Improve string normalization --- views/conflict.ejs | 6 +++++- views/label.ejs | 6 +++++- views/review.ejs | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/views/conflict.ejs b/views/conflict.ejs index a104df7..d9cc9fb 100644 --- a/views/conflict.ejs +++ b/views/conflict.ejs @@ -354,7 +354,11 @@ const toast = (element) => new bootstrap.Toast(element).show(); const normalize = (name) => { - return name.replaceAll(/\s+/g, " ").toLowerCase().trim(); + const coalesced = name ?? ""; + const normalized = coalesced.replaceAll(/\s+/g, " "); + const lowercase = normalized.toLowerCase(); + const trimmed = lowercase.trim(); + return (trimmed.length === 0) ? null : trimmed; }; const addOption = (label) => { diff --git a/views/label.ejs b/views/label.ejs index 8d094d5..1a41f3e 100644 --- a/views/label.ejs +++ b/views/label.ejs @@ -325,7 +325,11 @@ const toast = (element) => new bootstrap.Toast(element).show(); const normalize = (name) => { - return name.replaceAll(/\s+/g, " ").toLowerCase().trim(); + const coalesced = name ?? ""; + const normalized = coalesced.replaceAll(/\s+/g, " "); + const lowercase = normalized.toLowerCase(); + const trimmed = lowercase.trim(); + return (trimmed.length === 0) ? null : trimmed; }; renameModalForm.addEventListener("submit", (event) => { diff --git a/views/review.ejs b/views/review.ejs index aab5bfb..8d52d07 100644 --- a/views/review.ejs +++ b/views/review.ejs @@ -235,7 +235,11 @@ const toast = (element) => new bootstrap.Toast(element).show(); const normalize = (name) => { - return name.replaceAll(/\s+/g, " ").toLowerCase().trim(); + const coalesced = name ?? ""; + const normalized = coalesced.replaceAll(/\s+/g, " "); + const lowercase = normalized.toLowerCase(); + const trimmed = lowercase.trim(); + return (trimmed.length === 0) ? null : trimmed; }; const addOption = (label) => {