mirror of
https://github.com/owncast/owncast.git
synced 2025-11-02 11:56:57 +08:00
* fix(chat): fixes #4522 to stop people from setting invalid display names * fix(chat): also guard against non-ascii whitespace like non breaking space * Update web/utils/displayNameValidation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: handle additional whitespace * Update web/utils/displayNameValidation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Javascript formatting autofixes * fix: deduplicate running of validation * fix: fix error with useMemo * Update web/utils/displayNameValidation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update web/utils/displayNameValidation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Javascript formatting autofixes * fix: fix component rendering issue --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Owncast <owncast@owncast.online>
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
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)
|
|
}
|
|
}
|
|
|
|
// TestSafeStringWhitespace tests the MakeSafeStringOfLength function with whitespace-only input.
|
|
func TestSafeStringWhitespace(t *testing.T) {
|
|
testCases := []struct {
|
|
input string
|
|
expected string
|
|
name string
|
|
}{
|
|
{
|
|
input: " ",
|
|
expected: "",
|
|
name: "spaces only",
|
|
},
|
|
{
|
|
input: "\t\n\r",
|
|
expected: "",
|
|
name: "tab, newline, carriage return",
|
|
},
|
|
{
|
|
input: " \t \n \r ",
|
|
expected: "",
|
|
name: "mixed whitespace",
|
|
},
|
|
{
|
|
input: "",
|
|
expected: "",
|
|
name: "empty string",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := MakeSafeStringOfLength(tc.input, 30)
|
|
if result != tc.expected {
|
|
t.Errorf("Expected '%s', got '%s'", tc.expected, result)
|
|
}
|
|
})
|
|
}
|
|
}
|