summaryrefslogtreecommitdiffstats
path: root/routers/utils
diff options
context:
space:
mode:
Diffstat (limited to 'routers/utils')
-rw-r--r--routers/utils/utils.go17
-rw-r--r--routers/utils/utils_test.go17
2 files changed, 34 insertions, 0 deletions
diff --git a/routers/utils/utils.go b/routers/utils/utils.go
new file mode 100644
index 0000000000..6ead7d60e2
--- /dev/null
+++ b/routers/utils/utils.go
@@ -0,0 +1,17 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package utils
+
+import (
+ "strings"
+)
+
+// RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username
+func RemoveUsernameParameterSuffix(name string) string {
+ if index := strings.Index(name, " ("); index >= 0 {
+ name = name[:index]
+ }
+ return name
+}
diff --git a/routers/utils/utils_test.go b/routers/utils/utils_test.go
new file mode 100644
index 0000000000..fb56ac85c2
--- /dev/null
+++ b/routers/utils/utils_test.go
@@ -0,0 +1,17 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package utils
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRemoveUsernameParameterSuffix(t *testing.T) {
+ assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar (Foo Bar)"))
+ assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar"))
+ assert.Equal(t, "", RemoveUsernameParameterSuffix(""))
+}