@@ -129,6 +129,14 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
129129 "\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 " ,
130130 status : EscapeStatus {Escaped : true , HasBIDI : true , BadBIDI : true , HasLTRScript : true , HasRTLScript : true },
131131 },
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+ },
132140}
133141
134142func TestEscapeControlString (t * testing.T ) {
@@ -163,19 +171,27 @@ func TestEscapeControlReader(t *testing.T) {
163171 // lets add some control characters to the tests
164172 tests := make ([]escapeControlTest , 0 , len (escapeControlTests )* 3 )
165173 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+ }
166182 for _ , test := range escapeControlTests {
167183 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 )
170186 test .status .Escaped = true
171187 test .status .HasControls = true
172188 tests = append (tests , test )
173189 }
174190
175191 for _ , test := range escapeControlTests {
176192 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 )
179195 test .status .Escaped = true
180196 test .status .HasMarks = true
181197 tests = append (tests , test )
0 commit comments