From a55b78ccdb0d526b842a2c40eb5955e1b105d1b1 Mon Sep 17 00:00:00 2001
From: "A. Campbell" <allenc28@yahoo.com>
Date: Wed, 3 Aug 2016 12:59:02 -0400
Subject: [PATCH] Limit username length to 16 chars (#167)

---
 chat/sanitize.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/chat/sanitize.go b/chat/sanitize.go
index 8b162cd..b567825 100644
--- a/chat/sanitize.go
+++ b/chat/sanitize.go
@@ -3,10 +3,17 @@ package chat
 import "regexp"
 
 var reStripName = regexp.MustCompile("[^\\w.-]")
+const maxLength = 16
 
-// SanitizeName returns a name with only allowed characters.
+// SanitizeName returns a name with only allowed characters and a reasonable length
 func SanitizeName(s string) string {
-	return reStripName.ReplaceAllString(s, "")
+	s = reStripName.ReplaceAllString(s, "")
+	nameLength := maxLength
+	if len(s) <= maxLength {
+		nameLength = len(s)
+	}
+	s = s[:nameLength]
+	return s
 }
 
 var reStripData = regexp.MustCompile("[^[:ascii:]]")