Repository: TiddlyWiki/TiddlyWiki5 (JavaScript)

Issue:
[BUG] `filter` filter step throws an uncaught exception or returns wrong results when used with a soft parameter
**Describe the bug**
The `filter` operator, when its parameter is a variable transclusion, throws the following error:

> Uncaught TypeError: Cannot read property 'getVariable' of undefined

This occurs on every render. If the side-by-side previewer is currently on, I additionally cannot get into the tiddler that contains the filter to fix it and have to edit from outside TiddlyWiki to be able to use the wiki again.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a new wiki.
2. Paste the following MWE into a tiddler:

 ```
 \define fragment() [get[myfield]match<myvariable>]

 <$list filter="[tag[MyTag]filter<fragment>]">
   <<currentTiddler>><br>
 </$list>
 ```

3. Create a new tiddler tagged `MyTag` (the error only occurs when at least one input tiddler reaches the `filter` filter step).
4. The error appears as soon as the tag is added, if the first tiddler is still open.

Everything works as expected when `<myvalue>` is instead a hard parameter, e.g., `match[myvalue]`. When I use a field transclusion, there is no error, but it also doesn't appear to work correctly – with the filter fragment as `[get[myfield]match{!!myvalue}]`, I don't get any output even when the `myvalue` field on the listing tiddler is set to the same value as the `myfield` value on the tagged tiddler. As a sanity check, the filter `[tag[MyTag]get[myfield]match{!!myvalue}]`, starting in the same tiddler, does display one result (but obviously this filter doesn't do the same thing).

**Expected behavior**:
Either the filter works as expected (only tiddlers with tag `MyTag` whose `myfield` field matches the contents of the variable `myvariable` are listed, or (but I don't see any reason why this should be the case) TiddlyWiki at least recognizes that a variable transclusion for the parameter of the `filter` step is not supported and fails gracefully.

It does not make a difference whether the variable `myvariable` is actually defined. I didn't include any definition of the variable in the example above, but the error still occurs even if it has a value.

**Workaround**:
To get around this, you can use a hard parameter and use text substitution to get your desired match value into the fragment macro. This is annoying, but works fine.

**Desktop (please complete the following information):**
Tested on TiddlyDesktop and in Chromium 87.0.4280.141 64-bit on Linux. Originally found the bug on 5.1.23, confirmed it is still present in prerelease as of today.
[BUG] RSOE from undefined variable in subfilter
**Describe the bug**
RSOE with `Uncaught TypeError: Cannot read property 'getVariable' of undefined`

**To Reproduce**
```
<$vars sub="[match<undefined>]">
<$list filter="[[arbitrary]filter<sub>]">

</$list>
</$vars>
```



Discussion:
A potential alternative for now would be to use the filter run prefix equivalent:

```
<$list filter="[tag[MyTag]] :filter[get[myfield]match<myvariable>]">
  <<currentTiddler>><br>
</$list>
```

The fix should be simple, passing `options.widget` as the third argument in the call to `filterFn` in the filter operator:
https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/filters/filter.js#L23

I'm a bit too tied up to run the tests and prepare a PR at the moment, so hopefully someone else can pick up the ball from here.

Very interesting catch.  It seems the list widget doesn't pass on the `widget` object-pointer. so widget.getVariable() isn't defined. 

There should have been problems much earlier.
Same underlying issue as #5471 
>Same underlying issue as #5471

OK, closing this unless someone objects. Thanks guys.
@twMat please leave this open, while the cause is the same they will both need patching.



Patch:
diff --git a/core/modules/filters/filter.js b/core/modules/filters/filter.js
index 2e549672b08..4be552cff30 100644
--- a/core/modules/filters/filter.js
+++ b/core/modules/filters/filter.js
@@ -20,7 +20,7 @@ exports.filter = function(source,operator,options) {
 		results = [],
 		target = operator.prefix !== "!";
 	source(function(tiddler,title) {
-		var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]));
+		var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),options.widget);
 		if((list.length > 0) === target) {
 			results.push(title);
 		}


Test patch:
diff --git a/editions/test/tiddlers/tests/test-prefixes-filter.js b/editions/test/tiddlers/tests/test-prefixes-filter.js
index c089734b5ac..38800c45792 100644
--- a/editions/test/tiddlers/tests/test-prefixes-filter.js
+++ b/editions/test/tiddlers/tests/test-prefixes-filter.js
@@ -313,9 +313,12 @@ describe("'reduce' and 'intersection' filter prefix tests", function() {
 		rootWidget.makeChildWidgets();
 		var anchorWidget = rootWidget.children[0];
 		rootWidget.setVariable("larger-than-18","[get[text]length[]compare:integer:gteq[18]]");
+		rootWidget.setVariable("nr","18");
+		rootWidget.setVariable("larger-than-18-with-var","[get[text]length[]compare:integer:gteq<nr>]");
 		expect(wiki.filterTiddlers("[tag[textexample]] :filter[get[text]length[]compare:integer:gteq[18]]",anchorWidget).join(",")).toBe("Red wine,Cheesecake,Chocolate Cake");
 		expect(wiki.filterTiddlers("[tag[textexample]]",anchorWidget).join(",")).toBe("Sparkling water,Red wine,Cheesecake,Chocolate Cake");
 		expect(wiki.filterTiddlers("[tag[textexample]filter<larger-than-18>]",anchorWidget).join(",")).toBe("Red wine,Cheesecake,Chocolate Cake");
+		expect(wiki.filterTiddlers("[tag[textexample]filter<larger-than-18-with-var>]",anchorWidget).join(",")).toBe("Red wine,Cheesecake,Chocolate Cake");
 	})
 
 });