@@ -130,18 +130,12 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
130
130
status : EscapeStatus {Escaped : true , HasBIDI : true , BadBIDI : true , HasLTRScript : true , HasRTLScript : true },
131
131
},
132
132
{
133
- name : "BOM encoding UTF-8" ,
134
- text : string ([]byte {'\xef' , '\xbb' , '\xbf' }),
135
- result : string ([]byte {'\xef' , '\xbb' , '\xbf' }),
136
- status : EscapeStatus {},
137
- },
138
- {
139
- name : "BOM encoding UTF-16" ,
140
- text : string ([]byte {239 , 187 , 191 , 228 , 189 , 160 , 229 , 165 , 189 , 239 , 188 , 140 , 228 , 184 , 150 , 231 , 149 , 140 , 10 , 104 , 101 , 108 , 108 , 111 , 44 , 32 , 119 , 111 , 114 , 108 , 100 , 10 }),
141
- result : string ([]byte {239 , 187 , 191 , 228 , 189 , 160 , 229 , 165 , 189 , 239 , 188 , 140 , 228 , 184 , 150 , 231 , 149 , 140 , 10 , 104 , 101 , 108 , 108 , 111 , 44 , 32 , 119 , 111 , 114 , 108 , 100 , 10 }),
142
- status : EscapeStatus {
143
- HasLTRScript : true ,
144
- },
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 },
145
139
},
146
140
}
147
141
@@ -177,19 +171,27 @@ func TestEscapeControlReader(t *testing.T) {
177
171
// lets add some control characters to the tests
178
172
tests := make ([]escapeControlTest , 0 , len (escapeControlTests )* 3 )
179
173
copy (tests , escapeControlTests )
174
+
175
+ // if there is a BOM, we should keep the BOM
176
+ addPrefix := func (prefix string , s string ) string {
177
+ if strings .HasPrefix (s , "\xef \xbb \xbf " ) {
178
+ return s [:3 ] + prefix + s [3 :]
179
+ }
180
+ return prefix + s
181
+ }
180
182
for _ , test := range escapeControlTests {
181
183
test .name += " (+Control)"
182
- test .text = "\u001E " + test .text
183
- 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 )
184
186
test .status .Escaped = true
185
187
test .status .HasControls = true
186
188
tests = append (tests , test )
187
189
}
188
190
189
191
for _ , test := range escapeControlTests {
190
192
test .name += " (+Mark)"
191
- test .text = "\u0300 " + test .text
192
- 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 )
193
195
test .status .Escaped = true
194
196
test .status .HasMarks = true
195
197
tests = append (tests , test )
0 commit comments