Skip to content

Commit d52debf

Browse files
authored
Revert "fix: remove only one whitespace from data prefix #1044 (#1075)"
This reverts commit 3b41b01.
1 parent 9d98cc9 commit d52debf

2 files changed

Lines changed: 2 additions & 25 deletions

File tree

sse.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,8 @@ func trimHeader(size int, data []byte) []byte {
745745
return data
746746
}
747747
data = data[size:]
748-
if len(data) > 0 && data[0] == ' ' {
749-
data = data[1:]
750-
}
751-
if len(data) > 0 && data[len(data)-1] == '\n' {
752-
data = data[:len(data)-1]
753-
}
748+
data = bytes.TrimSpace(data)
749+
data = bytes.TrimSuffix(data, []byte("\n"))
754750
return data
755751
}
756752

sse_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,25 +323,6 @@ func TestEventSourceNoRetryRequired(t *testing.T) {
323323
assertEqual(t, true, strings.Contains(err.Error(), "400 Bad Request"))
324324
}
325325

326-
func TestGH1044TrimHeader(t *testing.T) {
327-
t.Run("data is nil", func(t *testing.T) {
328-
result := trimHeader(0, nil)
329-
assertNil(t, result)
330-
})
331-
332-
t.Run("data has double whitespace", func(t *testing.T) {
333-
data := []byte("data: double whitespace message")
334-
result := trimHeader(5, data)
335-
assertEqual(t, true, result[0] == ' ')
336-
})
337-
338-
t.Run("data has newline", func(t *testing.T) {
339-
data := []byte("data: newline message\n")
340-
result := trimHeader(5, data)
341-
assertEqual(t, true, result[len(result)-1] != '\n')
342-
})
343-
}
344-
345326
func TestEventSourceHTTPError(t *testing.T) {
346327
es := createEventSource(t, "", func(any) {}, nil)
347328
ts := createTestServer(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)