MCPcopy Index your code
hub / github.com/coder/coder / TestUISanitize

Function TestUISanitize

coderd/util/strings/strings_test.go:84–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestUISanitize(t *testing.T) {
85 t.Parallel()
86
87 for _, tt := range []struct {
88 s string
89 expected string
90 }{
91 {"normal text", "normal text"},
92 {"\tfoo \r\\nbar ", "foo bar"},
93 {"通常のテキスト", "通常のテキスト"},
94 {"foo\nbar", "foo bar"},
95 {"foo\tbar", "foo bar"},
96 {"foo\rbar", "foo bar"},
97 {"foo\x00bar", "foobar"},
98 {"\u202Eabc", "abc"},
99 {"\u200Bzero width", "zero width"},
100 {"foo\x1b[31mred\x1b[0mbar", "fooredbar"},
101 {"foo\u0008bar", "foobar"},
102 {"foo\x07bar", "foobar"},
103 {"foo\uFEFFbar", "foobar"},
104 {"<a href='javascript:alert(1)'>link</a>", "link"},
105 {"<style>body{display:none}</style>", ""},
106 {"<html>HTML</html>", "HTML"},
107 {"<br>line break", "line break"},
108 {"<link rel='stylesheet' href='evil.css'>", ""},
109 {"<img src=1 onerror=alert(1)>", ""},
110 {"<!-- comment -->visible", "visible"},
111 {"<script>alert('xss')</script>", ""},
112 {"<iframe src='evil.com'></iframe>", ""},
113 } {
114 t.Run(tt.expected, func(t *testing.T) {
115 t.Parallel()
116 actual := strings.UISanitize(tt.s)
117 assert.Equal(t, tt.expected, actual)
118 })
119 }
120}
121
122func TestCapitalize(t *testing.T) {
123 t.Parallel()

Callers

nothing calls this directly

Calls 3

UISanitizeFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected