Skip to content

Commit b1f2d9a

Browse files
committed
Added ASCII check to WriteString
fixes AndrewBurian#2
1 parent b4e6cbd commit b1f2d9a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

event.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"strconv"
66
"strings"
7+
"unicode"
78
)
89

910
// Event holds the structured data for an event.
@@ -120,7 +121,16 @@ func (e *Event) Write(p []byte) (int, error) {
120121

121122
// WriteString adds string data to the event.
122123
// Equivalent to calling Write([]byte(string))
124+
// Panics if provided with non-ascii input
123125
func (e *Event) WriteString(p string) {
126+
// check ASCII
127+
for _, c := range p {
128+
if c > unicode.MaxASCII {
129+
// TODO at next major version bump, convert this to return an error
130+
// instead of a blind panic
131+
panic("eventsource: WriteString: Attempt to write non-ascii string")
132+
}
133+
}
124134
// split event on newlines
125135
split := strings.Split(p, "\n")
126136
for _, entry := range split {

0 commit comments

Comments
 (0)