PrismarineJS / node-mojangson

A mojangson parser written in node.js
17 stars 9 forks source link

Parsing empty list and simplifying parse result throws error #34

Closed csjh closed 1 year ago

csjh commented 2 years ago

Recreation:

const mojangson = require("mojangson");
const empty_array_parse = mojangson.parse("{EmptyArray: []}");
console.log(mojangson.simplify(empty_array_parse));

Output:

Uncaught TypeError: Cannot read properties of undefined (reading 'map')
    at transform (/home/node_modules/mojangson/index.js:13:26)
    at simplify (/home/node_modules/mojangson/index.js:17:10)
    at /home/node_modules/mojangson/index.js:8:20
    at Array.reduce (<anonymous>)
    at transform (/home/node_modules/mojangson/index.js:7:33)
    at Object.simplify (/home/node_modules/mojangson/index.js:17:10)

I think it has something to do with there being no checks to verify the "value" key exists on line 13 of index.js. Adding if (value.value == undefined) return [] to index.js fixes it in this case but there might be exceptions.

Lianecx commented 1 year ago

I am getting the same error currently. Would love to see a fix

Lianecx commented 1 year ago

This has to be reopened, it is not fixed