ottypes / json0

Version 0 of the JSON OT type
447 stars 64 forks source link

json.apply using null object before error thrown #10

Open amillward opened 9 years ago

amillward commented 9 years ago

From json.apply:

for (var j = 0; j < c.p.length; j++) {
  var p = c.p[j];
  parent = elem;
  parentKey = key;
  elem = elem[key];
  key = p;
  if (parent == null)
    throw new Error('Path invalid');
}

If parent is null, this code will break on elem = elem[key];. It should be:

for (var j = 0; j < c.p.length; j++) {
  var p = c.p[j];
  parent = elem;
  if (parent == null)
    throw new Error('Path invalid');
  parentKey = key;
  elem = elem[key];
  key = p;

}