RyanMarcus / dirty-json

A parser for invalid JSON
GNU Affero General Public License v3.0
307 stars 30 forks source link

Handle null and empty string #37

Open maxsatula opened 3 years ago

maxsatula commented 3 years ago

This example

require('dirty-json').parse(null)

Returns null as expected, but whines every time:

dirty-json got valid JSON that failed with the custom parser. We're returning the valid JSON, but please file a bug report here: https://github.com/RyanMarcus/dirty-json/issues -- the JSON that caused the failure was: null

Passing an empty string throws an exception:

require('dirty-json').parse("")

Uncaught TypeError: Cannot read property 'type' of undefined

It is negotiable though what is supposed to be returned instead of an exception. An empty string or an empty object?

Also, passing undefined (not sure who might want that) gives another exception

require('dirty-json').parse(undefined)

Uncaught TypeError: Cannot read property 'length' of undefined

Not sure if you want to handle undefined at all, I just checked it for no apparent reason while creating this issue. Also, boolean values (I know, this module is supposed to process strings, what am I talking about) have the same behavior as null, the same value returned, but with a warning.