diff --git a/core/modules/filters/listops.js b/core/modules/filters/listops.js index ab194339a..02d92831a 100644 --- a/core/modules/filters/listops.js +++ b/core/modules/filters/listops.js @@ -87,7 +87,8 @@ exports.butlast = function(source,operator,options) { source(function(tiddler,title) { results.push(title); }); - return results.slice(0,-count); + var index = count === 0 ? results.length : -count; + return results.slice(0,index); }; exports.bl = exports.butlast; diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 7fba38376..18545221b 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -371,6 +371,7 @@ Tests the filtering mechanism. expect(wiki.filterTiddlers("[sort[title]reverse[]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin"); expect(wiki.filterTiddlers("[sort[title]reverse[x]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin"); expect(wiki.filterTiddlers("[sort[title]butlast[]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three"); + expect(wiki.filterTiddlers("[sort[title]butlast[0]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne"); expect(wiki.filterTiddlers("[sort[title]butlast[2]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one"); expect(wiki.filterTiddlers("[sort[title]butlast[11]]").join(",")).toBe(""); expect(wiki.filterTiddlers("[sort[title]butlast[x]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three"); diff --git a/editions/tw5.com/tiddlers/filters/butlast.tid b/editions/tw5.com/tiddlers/filters/butlast.tid index c88346884..fd79ea7b3 100644 --- a/editions/tw5.com/tiddlers/filters/butlast.tid +++ b/editions/tw5.com/tiddlers/filters/butlast.tid @@ -1,5 +1,5 @@ created: 20140410103123179 -modified: 20150203191930000 +modified: 20220226043344258 tags: [[Filter Operators]] [[Order Operators]] title: butlast Operator type: text/vnd.tiddlywiki @@ -10,4 +10,6 @@ op-parameter: an integer, defaulting to 1 op-parameter-name: N op-output: all but the last <<.place N>> input titles +<<.from-version "5.2.2">> The <<.op butlast>> operator returns the input list unchanged if <<.place N>> is 0. This is consistent with the behaviour of the [[rest Operator]]. + <<.operator-examples "butlast">> diff --git a/editions/tw5.com/tiddlers/filters/examples/butlast.tid b/editions/tw5.com/tiddlers/filters/examples/butlast.tid index 6a0e2b235..9f67e52cd 100644 --- a/editions/tw5.com/tiddlers/filters/examples/butlast.tid +++ b/editions/tw5.com/tiddlers/filters/examples/butlast.tid @@ -1,5 +1,5 @@ created: 20150118134611000 -modified: 20150118183143000 +modified: 20220226043344258 tags: [[butlast Operator]] [[Operator Examples]] title: butlast Operator (Examples) type: text/vnd.tiddlywiki @@ -7,5 +7,6 @@ type: text/vnd.tiddlywiki <<.using-days-of-week>> <<.operator-example 1 "[list[Days of the Week]butlast[]]">> -<<.operator-example 2 "[list[Days of the Week]butlast[2]]">> -<<.operator-example 3 "A B C D E F G H I J K L M +[butlast[7]]">> +<<.operator-example 2 "[list[Days of the Week]butlast[0]]">> +<<.operator-example 3 "[list[Days of the Week]butlast[2]]">> +<<.operator-example 4 "A B C D E F G H I J K L M +[butlast[7]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/rest.tid b/editions/tw5.com/tiddlers/filters/examples/rest.tid index 61b35b119..a9d2ab416 100644 --- a/editions/tw5.com/tiddlers/filters/examples/rest.tid +++ b/editions/tw5.com/tiddlers/filters/examples/rest.tid @@ -1,5 +1,5 @@ created: 20150118134611000 -modified: 20150123211722000 +modified: 20220226043344258 tags: [[rest Operator]] [[Operator Examples]] title: rest Operator (Examples) type: text/vnd.tiddlywiki @@ -7,5 +7,6 @@ type: text/vnd.tiddlywiki <<.using-days-of-week>> <<.operator-example 1 "[list[Days of the Week]rest[]]">> -<<.operator-example 2 "[list[Days of the Week]rest[3]]">> -<<.operator-example 3 "Z Y X W V U T S R Q P O +[rest[5]]">> +<<.operator-example 2 "[list[Days of the Week]rest[0]]">> +<<.operator-example 3 "[list[Days of the Week]rest[3]]">> +<<.operator-example 4 "Z Y X W V U T S R Q P O +[rest[5]]">>