@@ -129,6 +129,14 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
129
129
"\n " + `if access_level != "user<span class="escaped-code-point" data-escaped="[U+202E]"><span class="char">` + "\u202e " + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066 " + `</span></span>// Check if admin<span class="escaped-code-point" data-escaped="[U+2069]"><span class="char">` + "\u2069 " + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066 " + `</span></span>" {` + "\n " ,
130
130
status : EscapeStatus {Escaped : true , HasBIDI : true , BadBIDI : true , HasLTRScript : true , HasRTLScript : true },
131
131
},
132
+ {
133
+ // UTF-8/16/32 all use the same codepoint for BOM
134
+ // Gitea could read UTF-16/32 content and convert into UTF-8 internally then render it, so we only process UTF-8 internally
135
+ name : "UTF BOM" ,
136
+ text : "\xef \xbb \xbf test" ,
137
+ result : "\xef \xbb \xbf test" ,
138
+ status : EscapeStatus {HasLTRScript : true },
139
+ },
132
140
}
133
141
134
142
func TestEscapeControlString (t * testing.T ) {
@@ -163,19 +171,27 @@ func TestEscapeControlReader(t *testing.T) {
163
171
// lets add some control characters to the tests
164
172
tests := make ([]escapeControlTest , 0 , len (escapeControlTests )* 3 )
165
173
copy (tests , escapeControlTests )
174
+
175
+ // if there is a BOM, we should keep the BOM
176
+ addPrefix := func (prefix , s string ) string {
177
+ if strings .HasPrefix (s , "\xef \xbb \xbf " ) {
178
+ return s [:3 ] + prefix + s [3 :]
179
+ }
180
+ return prefix + s
181
+ }
166
182
for _ , test := range escapeControlTests {
167
183
test .name += " (+Control)"
168
- test .text = "\u001E " + test .text
169
- test .result = `<span class="escaped-code-point" data-escaped="[U+001E]"><span class="char">` + "\u001e " + `</span></span>` + test .result
184
+ test .text = addPrefix ( "\u001E " , test .text )
185
+ test .result = addPrefix ( `<span class="escaped-code-point" data-escaped="[U+001E]"><span class="char">` + "\u001e " + `</span></span>` , test .result )
170
186
test .status .Escaped = true
171
187
test .status .HasControls = true
172
188
tests = append (tests , test )
173
189
}
174
190
175
191
for _ , test := range escapeControlTests {
176
192
test .name += " (+Mark)"
177
- test .text = "\u0300 " + test .text
178
- test .result = `<span class="escaped-code-point" data-escaped="[U+0300]"><span class="char">` + "\u0300 " + `</span></span>` + test .result
193
+ test .text = addPrefix ( "\u0300 " , test .text )
194
+ test .result = addPrefix ( `<span class="escaped-code-point" data-escaped="[U+0300]"><span class="char">` + "\u0300 " + `</span></span>` , test .result )
179
195
test .status .Escaped = true
180
196
test .status .HasMarks = true
181
197
tests = append (tests , test )
0 commit comments