Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ class Parser extends Transform {
parse.pointer++
this.push(msg)
} catch (err) {
const rem = '[' + str.slice(parse.pointer, last + 2) + ']'
for (const msg of JSON.parse(rem)) {
this.push(msg)
try {
const rem = '[' + str.slice(parse.pointer, last + 2) + ']'
for (const msg of JSON.parse(rem)) {
this.push(msg)
}
parse.pointer = last + 3
} catch (err) {
cb(err)
return
}
parse.pointer = last + 3
}
}
this._buffer = str.slice(parse.pointer)
Expand Down
23 changes: 23 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,26 @@ tape('chunked', function (t) {
t.end()
})
})

tape('invalid json', function (t) {
t.plan(2)
const parse = parser()
const expected = [sample()]
const s = '{"traceEvents":[' + JSON.stringify(expected[0]) + ', {"x":"x"]}},]}'

for (var i = 0; i < s.length; i++) {
parse.write(s.slice(i, i + 1))
}
parse.end()

parse
.on('data', function (data) {
t.same(data, expected.shift())
})
.on('error', function (error) {
t.ok(error)
})
.on('end', function () {
t.fail()
})
})