Skip to content

Commit 7ed80dc

Browse files
authored
Fix NPE when reviver function encounters a null value. (#2)
1 parent e927eb8 commit 7ed80dc

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 4.1.1
2+
3+
* Fix NPE when reviver function encounters a null value.
4+
15
### 4.1.0
26

37
* Added a new replacer function feature, `JSONZ.LITERALLY_AS`, allowing a replacer function to explicitly determine how a value will be rendered when stringified.

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ module.exports = function parse(text, reviver, newOptions) {
11971197
function internalize(holder, name, reviver) {
11981198
const value = holder[name];
11991199

1200-
if (typeof value === 'object') {
1200+
if (value && typeof value === 'object') {
12011201
const keys = Object.keys(value);
12021202

12031203
for (const key of keys) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-z",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "JSON for everyone.",
55
"main": "lib/index.min.js",
66
"types": "lib/index.d.ts",

test/parse.spec.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ describe('JSONZ', () => {
556556

557557
it('parse(text, reviver)', () => {
558558
expect(
559-
JSONZ.parse('{a:1,b:2}', (k, v) => (k === 'a') ? 'revived' : v)).to.deep.equal(
560-
{ a: 'revived', b: 2 },
559+
JSONZ.parse('{a:1,b:2,c:null}', (k, v) => (k === 'a') ? 'revived' : v)).to.deep.equal(
560+
{ a: 'revived', b: 2, c: null },
561561
'modifies property values'
562562
);
563563

0 commit comments

Comments
 (0)