Add payload validation before parsing JSON
This commit is contained in:
parent
e6afc0d797
commit
7ca1f94160
|
|
@ -44,8 +44,10 @@ async function connect(url: string, signal: AbortSignal) {
|
|||
for (const part of parts) {
|
||||
const line = part.split('\n').find(l => l.startsWith('data:'))
|
||||
if (!line) continue
|
||||
const payload = line.slice(5).trim()
|
||||
if (!payload) continue
|
||||
try {
|
||||
const event: ToesEvent = JSON.parse(line.slice(5).trim())
|
||||
const event: ToesEvent = JSON.parse(payload)
|
||||
_listeners.forEach(l => {
|
||||
if (l.types.includes(event.type)) l.callback(event)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user