fix: allow filters with ( ) and " delimiters in Boolean filters #2759
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Major fix of Boolean filters, to allow use of
(
,)
and"
in filters within Boolean expressions.Note: more improvements are coming so I am not updating the documentation yet.
Caveat
The one current caveat with this implementation is that it still does not work for filters the end with any of the characters
()"
, as they are swallowed up and treated as delimiters.So for example, this filter:
is interpreted as this simplified line - note the stray
"
:where
f1
is this - note the missing"
:Workarounds
filter by function
instructions are very likely to end with)
, due to the expression often ending with a function call.Available workarounds:
;
at the end of anyfilter by function
that ends in)
or"
.filter by function
to be a singlefilter by function
that uses JavaScript&&
,||
and!
.Motivation and Context
How has this been tested?
Screenshots (if appropriate)
Examples of searches that now work, followed by their
explain
output:Example 1 - containing a regular expression with ()
( description regex matches /(buy|order|voucher|lakeland|purchase|\spresent)/i ) OR ( path includes Home/Shopping )
explain
output:Example 2
(path includes (some example) OR (path includes )some example()
explain
output:Example 3 - complex combination of custom filters
Important: Note that the following only works because every filter expression that ends with
)
is followed by a;
, to prevent the)
being wrongly treated as part of the Boolean logic.( filter by function ! 'NON_TASK,CANCELLED'.includes(task.status.type); ) OR ( filter by function const date = task.due.moment; return date ? !date.isValid() : false; ) OR ( filter by function task.due.moment?.isSameOrBefore(moment(), 'day') || false; ) OR ( filter by function task.urgency.toFixed(2) === 1.95.toFixed(2); ) OR ( filter by function (!task.isRecurring) && task.originalMarkdown.includes('馃攣'); ) OR ( filter by function task.file.path.toLocaleLowerCase() === 'TASKS RELEASES/4.1.0 RELEASE.MD'.toLocaleLowerCase(); ) OR ( filter by function const taskDate = task.due.moment; const now = moment(); return taskDate?.isSame(now, 'day') || ( !taskDate && task.heading?.includes(now.format('YYYY-MM-DD')) ) || false; ) OR ( filter by function const wanted = '#context/home'; return task.heading?.includes(wanted) || task.tags.find( (tag) => tag === wanted ) && true || false; )
explain
output:Types of changes
Changes visible to users:
fix
- non-breaking change which fixes an issue)docs
- improvements to any documentation content for users)Internal changes:
test
- additions and improvements to unit tests and the smoke tests)Checklist
yarn run lint
.Terms