[Pkg-javascript-commits] [backbone] 66/173: Fixed Collection#set regression when parse returns falsy value
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 07:44:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository backbone.
commit 19b88d2c2d1885984c7391c5590ef09086083e78
Author: Ilia Ablamonov <ilia at flamefork.ru>
Date: Tue Dec 1 10:00:36 2015 +0400
Fixed Collection#set regression when parse returns falsy value
Fixes #3871
---
backbone.js | 2 +-
test/collection.js | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/backbone.js b/backbone.js
index 17ea2c0..1909c46 100644
--- a/backbone.js
+++ b/backbone.js
@@ -824,7 +824,7 @@
if (options.parse && !this._isModel(models)) models = this.parse(models, options);
var singular = !_.isArray(models);
- models = singular ? [models] : models.slice();
+ models = singular ? (models ? [models] : []) : models.slice();
var at = options.at;
if (at != null) at = +at;
diff --git a/test/collection.js b/test/collection.js
index d6341be..c154566 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -1817,4 +1817,12 @@
model.trigger('change');
});
+ QUnit.test('#3871 - falsy parse result creates empty collection', function(assert) {
+ var collection = new (Backbone.Collection.extend({
+ parse: function (data, options) {}
+ }));
+ collection.set('', { parse: true });
+ assert.equal(collection.length, 0);
+ });
+
})();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list