Skip to content

Commit 81d2ced

Browse files
author
Gusted
committed
Add UTF-16 test case
1 parent be1a4bb commit 81d2ced

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

modules/charset/escape.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func EscapeControlReader(text io.Reader, output io.Writer) (escaped EscapeStatus
6969
lineHasBIDI := false
7070
lineHasRTLScript := false
7171
lineHasLTRScript := false
72-
7372
readingloop:
7473
for err == nil {
7574
n, err = text.Read(buf[readStart:])
@@ -79,6 +78,7 @@ readingloop:
7978

8079
for i < len(bs) {
8180
r, size := utf8.DecodeRune(bs[i:])
81+
8282
// Now handle the codepoints
8383
switch {
8484
case r == utf8.RuneError:
@@ -145,7 +145,7 @@ readingloop:
145145
}
146146
writePos = i + size
147147
// 65279 == BOM rune.
148-
case unicode.Is(unicode.C, r) && r != rune(65279):
148+
case r != rune(65279) && unicode.Is(unicode.C, r):
149149
escaped.Escaped = true
150150
escaped.HasControls = true
151151
if writePos < i {

modules/charset/escape_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
135135
result: string([]byte{'\xef', '\xbb', '\xbf'}),
136136
status: EscapeStatus{},
137137
},
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+
},
145+
},
138146
}
139147

140148
func TestEscapeControlString(t *testing.T) {

0 commit comments

Comments
 (0)