[Pkg-javascript-commits] [backbone] 136/173: Fix #3951: options.index should never exceed collection.length
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 07:44:13 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 b0161947eb731f936cb986b1cf669af9370adbc9
Author: Adam Krebs <amk528 at cs.nyu.edu>
Date: Thu Feb 4 15:01:59 2016 -0500
Fix #3951: options.index should never exceed collection.length
---
backbone.js | 1 +
test/collection.js | 11 ++++++-----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/backbone.js b/backbone.js
index 34a8a0c..7999e98 100644
--- a/backbone.js
+++ b/backbone.js
@@ -835,6 +835,7 @@
var at = options.at;
if (at != null) at = +at;
+ if (at > this.length) at = this.length;
if (at < 0) at += this.length + 1;
var set = [];
diff --git a/test/collection.js b/test/collection.js
index 40a08f1..26c1f4a 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -1739,13 +1739,14 @@
assert.equal(c2.modelId(m.attributes), void 0);
});
- QUnit.test('#3039: adding at index fires with correct at', function(assert) {
- assert.expect(3);
- var collection = new Backbone.Collection([{at: 0}, {at: 4}]);
- collection.on('add', function(model, coll, options) {
+ QUnit.test("#3039 #3951: adding at index fires with correct at", function(assert) {
+ assert.expect(4);
+ var col = new Backbone.Collection([{at: 0}, {at: 4}]);
+ col.on('add', function(model, col, options) {
assert.equal(model.get('at'), options.index);
});
- collection.add([{at: 1}, {at: 2}, {at: 3}], {at: 1});
+ col.add([{at: 1}, {at: 2}, {at: 3}], {at: 1});
+ col.add({at: 5}, {at: 10});
});
QUnit.test('#3039: index is not sent when at is not specified', function(assert) {
--
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