Skip to content

Commit

Permalink
fix: #93 repair undefined values by replacing them with null
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 13, 2023
1 parent be7f4de commit af348d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/jsonrepair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ describe('jsonRepair', () => {
strictEqual(jsonrepair('{"a":'), '{"a":null}')
})

it('should repair undefined values', () => {
strictEqual(jsonrepair('{"a":undefined}'), '{"a":null}')
strictEqual(jsonrepair('[undefined]'), '[null]')
strictEqual(jsonrepair('undefined'), 'null')
})

it('should escape unescaped control characters', () => {
strictEqual(jsonrepair('"hello\bworld"'), '"hello\\bworld"')
strictEqual(jsonrepair('"hello\fworld"'), '"hello\\fworld"')
Expand Down
2 changes: 1 addition & 1 deletion src/jsonrepair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export function jsonrepair(text: string): string {
}

const symbol = text.slice(start, i)
output += JSON.stringify(symbol)
output += symbol === 'undefined' ? 'null' : JSON.stringify(symbol)

return true
}
Expand Down

0 comments on commit af348d7

Please sign in to comment.