diff --git a/core/modules/filters/listops.js b/core/modules/filters/listops.js index 02d92831a..89bd8eeb7 100644 --- a/core/modules/filters/listops.js +++ b/core/modules/filters/listops.js @@ -58,6 +58,7 @@ Last entry/entries in list exports.last = function(source,operator,options) { var count = $tw.utils.getInt(operator.operand,1), results = []; + if(count === 0) return results; source(function(tiddler,title) { results.push(title); }); diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 9e2f53b1a..727f64ca4 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -365,6 +365,7 @@ Tests the filtering mechanism. expect(wiki.filterTiddlers("[sort[title]first[8]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three"); expect(wiki.filterTiddlers("[sort[title]first[x]]").join(",")).toBe("$:/ShadowPlugin"); expect(wiki.filterTiddlers("[sort[title]last[]]").join(",")).toBe("TiddlerOne"); + expect(wiki.filterTiddlers("[sort[title]last[0]]").join(",")).toBe(""); expect(wiki.filterTiddlers("[sort[title]last[2]]").join(",")).toBe("Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[8]]").join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]last[x]]").join(",")).toBe("TiddlerOne");