From 246751be1ba45cf94be907dc0804ae3f5193e149 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Wed, 25 Oct 2023 19:14:49 +0700 Subject: [PATCH] Fix last filter operator when zero items selected (#7809) Previously, [last[0]] was incorrectly returning the entire list. It now returns zero items as it should. --- core/modules/filters/listops.js | 1 + editions/test/tiddlers/tests/test-filters.js | 1 + 2 files changed, 2 insertions(+) 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");