From c81c0dd22a7779148c4890cfd4bbf490054f06f1 Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 31 Jan 2019 17:06:36 +0100 Subject: Update vendor, move to labstack/echo/v4 Fixes #698 --- .../shazow/ssh-chat/internal/sanitize/sanitize.go | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 vendor/github.com/shazow/ssh-chat/internal/sanitize/sanitize.go (limited to 'vendor/github.com/shazow/ssh-chat/internal/sanitize') diff --git a/vendor/github.com/shazow/ssh-chat/internal/sanitize/sanitize.go b/vendor/github.com/shazow/ssh-chat/internal/sanitize/sanitize.go new file mode 100644 index 00000000..ed532c97 --- /dev/null +++ b/vendor/github.com/shazow/ssh-chat/internal/sanitize/sanitize.go @@ -0,0 +1,28 @@ +package sanitize + +import "regexp" + +var reStripName = regexp.MustCompile("[^\\w.-]") + +const maxLength = 16 + +// Name returns a name with only allowed characters and a reasonable length +func Name(s string) string { + s = reStripName.ReplaceAllString(s, "") + nameLength := maxLength + if len(s) <= maxLength { + nameLength = len(s) + } + s = s[:nameLength] + return s +} + +var reStripData = regexp.MustCompile("[^[:ascii:]]|[[:cntrl:]]") + +// Data returns a string with only allowed characters for client-provided metadata inputs. +func Data(s string, maxlen int) string { + if len(s) > maxlen { + s = s[:maxlen] + } + return reStripData.ReplaceAllString(s, "") +} -- cgit v1.2.3