diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 9217f72..3bd6192 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -260,3 +260,9 @@ testHelpers.dev.devOnlyTest("a warning is given for `callMethodsOnObservables: t QUnit.equal(teardown(), 1, "warning displayed"); }); +QUnit.test("writing to a null observable is ignored", function(){ + observeReader.write({},"foo.bar", "value"); + observeReader.write(null,"bar", "value"); + observeReader.write(null,"foo.bar", "value"); + QUnit.ok(true, "all passed without error"); +}); diff --git a/can-stache-key.js b/can-stache-key.js index c46b216..7c18a8c 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -294,7 +294,6 @@ observeReader = { var last; options = options || {}; - if(keys.length > 1) { last = keys.pop(); parent = observeReader.read(parent, keys, options).value; @@ -302,6 +301,9 @@ observeReader = { } else { last = keys[0]; } + if(!parent) { + return; + } var keyValue = peek(parent, last.key); // here's where we need to figure out the best way to write