]> WPIA git - gigi.git/blobdiff - src/club/wpia/gigi/output/NameInput.java
Merge "fix: ensure no blanks are entered between name parts and hyphens"
[gigi.git] / src / club / wpia / gigi / output / NameInput.java
index 11c8de57097ed863571a84b2482527d51f1f4a1e..272c06e4249a344a8ee63df3485b8ac9ba62a57c 100644 (file)
@@ -8,8 +8,8 @@ import javax.servlet.http.HttpServletRequest;
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.Name;
 import club.wpia.gigi.dbObjects.NamePart;
-import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
+import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.localisation.Language;
 import club.wpia.gigi.output.template.Outputable;
 import club.wpia.gigi.output.template.Template;
@@ -74,8 +74,11 @@ public class NameInput implements Outputable {
 
     public NamePart[] getNameParts() throws GigiApiException {
         if ("single".equals(scheme)) {
+            if (name == null || name.trim().isEmpty()) {
+                throw new GigiApiException("requires at least one character in the single name");
+            }
             return new NamePart[] {
-                    new NamePart(NamePartType.SINGLE_NAME, name)
+                    new NamePart(NamePartType.SINGLE_NAME, name.trim())
             };
         }
         String[] fparts = split(fname);
@@ -103,6 +106,9 @@ public class NameInput implements Outputable {
         if (toSplit == null || toSplit.trim().isEmpty()) {
             return new String[0];
         }
+        toSplit = toSplit.replaceAll("(?>[\\p{Z}\\s]*)([\u002d\u058a\u05be\u1806\u2010\u2011\u2012\u2013\u2014\u2015\u2e3a\u2e3b\ufe58\ufe63\uff0d])(?>[\\p{Z}\\s]*)", "-");
+        toSplit = toSplit.replaceAll("(?>[\\p{Z}\\s]+)", " ").trim();
+
         return toSplit.split(" ");
     }