From 27fbfc5ffc811106df222ce8f06d9b07faddcead Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 15 Mar 2018 17:16:03 -0500 Subject: [PATCH] fixes bug with two-way bindings trying to set input empty string value to an observable that doesn't exist yet --- can-stache-key-test.js | 6 ++++++ can-stache-key.js | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) 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