obsidian-tasks
obsidian-tasks copied to clipboard
Work out how to prevent `path regex matches /a/b/c/d/` from confusingly only searching `path regex matches /a/`.
From code review in https://github.com/obsidian-tasks-group/obsidian-tasks/pull/1015
Open an Issue against this?
Fixable with another regex. 😉😂🤣🤪
Originally posted by @elight in https://github.com/obsidian-tasks-group/obsidian-tasks/pull/1015#discussion_r945393546
Expected Behavior
path regex matches /a/b/c/d/
Should give an error message, something along the lines of:
An unescaped delimiter must be escaped; in most languages with a backslash ()
So that the user can work out that the correct search is:
path regex matches /\a/b\/c\/d/
Current behaviour
The search proceeds, doing this search, and potentially matching many unwanted hits:
path regex matches /a/
Steps to reproduce
Construct a search similar to the above, and run in Tasks 1.12.0, when it is relased.
Or open the file Regular Expression Searches.md
in the Tasks-Demo vault, and read the section 'Extra slashes truncate the query'
Or run this test, and remove all the failing
text:
https://github.com/obsidian-tasks-group/obsidian-tasks/blob/60c5cd45d6d236f3fe8b4b1628b03953a4c19867/tests/Query/Filter/PathField.test.ts#L158-L187
Which Operating Systems are you using?
- [ ] Android
- [ ] iPhone/iPad
- [ ] Linux
- [x] macOS
- [ ] Windows
Obsidian Version
0.15.9
Tasks Plugin Version
1.12.0 (pre-release)
Checks
- [ ] I have tried it with all other plugins disabled and the error still occurs
Suggested fix
Current behaviour
I believe that the problem is that the regular expression is the problem:
https://github.com/obsidian-tasks-group/obsidian-tasks/blob/114c8cd7614bbcba1f746b742658c9bcf99fd5bf/src/Query/Filter/TextField.ts#L32-L33
It gets as much of the regex as is valid, and ignores any later text.
This hides any errors from the user.
Requested behaviour
- I would like the full regular expression that is supplied by the user to be passed to the regex library
- and then for Tasks to check if there were any error messages detected
- and if there was an error, report it the the user and then refuse to search.
In other words, I don't feel that it is Tasks' job to validate the regex supplied to the user.
I feel that the regex library should do this, as it is bound to do a better and more informative job than we can possibly do.
😂 that you included my original comment.
A very rough idea for an approach to a solution... It will probably be possible to get the regular expression's source and any modifiers, and see if it shorter than the user's supplied source. If so, some of the user's text has effectively been discarded.
Search for regex a/b/c/d
is interpreted as /b/
.