Skip to content

Commit 3c66921

Browse files
jeroencranendonk-wfjeffbski
authored andcommitted
Fixed value check on makeCursor
Certain code paths call makeCursor with four arguments, with 'value' undefined. Since arguments.length is still four in this case, the value is not retrieved from rootData, and an incorrect cursor type can be generated.
1 parent 6b60746 commit 3c66921

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

contrib/cursor/__tests__/Cursor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ describe('Cursor', () => {
4949
expect(deepCursor.deref()).toBe(data.getIn(Immutable.fromJS(['a', 'b'])));
5050
});
5151

52+
it('cursor return new cursors of correct type', () => {
53+
var data = Immutable.fromJS({ a: [1, 2, 3] });
54+
var cursor = Cursor.from(data);
55+
var deepCursor = <any>cursor.cursor('a');
56+
expect(deepCursor.findIndex).toBeDefined();
57+
});
58+
5259
it('can be treated as a value', () => {
5360
var data = Immutable.fromJS(json);
5461
var cursor = Cursor.from(data, ['a', 'b']);

contrib/cursor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ IndexedCursor.prototype = IndexedCursorPrototype;
220220
var NOT_SET = {}; // Sentinel value
221221

222222
function makeCursor(rootData, keyPath, onChange, value) {
223-
if (arguments.length < 4) {
223+
if (value === void 0) {
224224
value = rootData.getIn(keyPath);
225225
}
226226
var size = value && value.size;

0 commit comments

Comments
 (0)