Sanitize+truncate display names on registration+change. For #2527

This commit is contained in:
Gabe Kangas
2022-12-28 21:30:06 -08:00
parent 51c804f6ae
commit 0c03773c4c
4 changed files with 68 additions and 5 deletions

32
utils/strings_test.go Normal file
View File

@@ -0,0 +1,32 @@
package utils
import (
"fmt"
"testing"
)
// TestStripHTML tests the StripHTML function.
func TestStripHTML(t *testing.T) {
requestedString := `<p><img src="img.png"/>Some text</p>`
expectedResult := `Some text`
result := StripHTML(requestedString)
fmt.Println(result)
if result != expectedResult {
t.Errorf("Expected %s, got %s", expectedResult, result)
}
}
// TestSafeString tests the TestSafeString function.
func TestSafeString(t *testing.T) {
requestedString := `<p><img src="img.png"/> Some text blah blah blah blah blah blahb albh</p>`
expectedResult := `Some te`
result := MakeSafeStringOfLength(requestedString, 10)
fmt.Println(result)
if result != expectedResult {
t.Errorf("Expected %s, got %s", expectedResult, result)
}
}