Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong error message in case of using RegExpr with nested "[...]"in Advanced Search #4267

Open
CarpeDiemKopi opened this issue Sep 20, 2019 · 13 comments

Comments

@CarpeDiemKopi
Copy link

see Task: Filter all tiddlers created between 01.09.2019 and 15.09.2019. How/where to find information/documentation to get this task done?

@Jermolene
Copy link
Owner

Thanks @CarpeDiemKopi -- its actually helpful if GitHub issues can be self-contained, and not require reading a thread elsewhere to understand what is being requested. The best way of reporting a problem is to say what you did, what happened, and what you expected to happen. So this one might have said:

I tried the string [regexp:created[201909(0[1-9]|1[0-5]))]] in the advanced search "Filters" tab, and received the error message "Filter error: Missing [ in filter expression". The error message is confusing. It would have been better if the message was "XXXX"

I don't know what error message you were expecting, but this one is fairly typical in that it is necessarily written from the point of the view of the software as it tries to make sense of the input. Here, it is reading the regexp operator as having the operand 201909(0[1-9. It then treats |1 as the next operator, with the operand 0-5. It then looks for the next operator, which should be terminated by the [, { etc that marks the start of the operand. Hence the error about the missing [.

It's hard to come up with better wording that still covers all of the situations in which the error can arise, but I'm open to suggestions.

@CarpeDiemKopi
Copy link
Author

CarpeDiemKopi commented Sep 22, 2019

Thanks for the answer @Jermolene. Point taken. I should have put a summary of the thread here before.

You write from the programmer's point of view. As a user I think that after the second bracket I am in the world of RegExp: [regexp:created[ and here you're entering the RegExp universum ]].

  • RegExp => correct.
  • two left square brackets, two right square brackets, order of brackets => correct

=> I don't expect any error messages!

( I expect the ability to escape brackets inside regular expressions to avoid this error message.
or
I expect the ability to define variables at this point to avoid this error message.)

@CarpeDiemKopi
Copy link
Author

CarpeDiemKopi commented Sep 23, 2019

I analyzed the problem in filter.js and the solution is surprisingly simple:

parseFilterOperation must catch the operator "regexp" and then determine nextBracketPos with "]]" from the end of the string.

parseFilter must not throw any error if filterString contains regexp:

See in my fork this commit: case regex: operator

It looks like a lot more because I've added several console.log commands to be able to set breakpoints.

@TiddlyTweeter
Copy link
Contributor

TiddlyTweeter commented Sep 23, 2019

Whilst I'm very keen on anything that makes JS regex easier to work with I think allowing [...] in the context of core TW filtering could be somewhat problemmatic.

The issue is that the filter syntax "reserves" [...] for its own use. The PR would create an anomaly in docs.

So, one one hand I'm in favour of it; on the other I think its adds yet more complexity to TW filter syntax that could be confusing??

TiddlyTweeter referenced this issue in CarpeDiemKopi/TiddlyWiki5 Sep 23, 2019
@CarpeDiemKopi
Copy link
Author

But regex has also certain characters for special use. I think that a regex user can distinguish where he has to use WikiText or RegExp special chars. And for this user, it is incomprehensible that square brackets are not recognized in a regular expression.

Let's look at the error message in the following screenshot:
grafik

This is a regex message.

WikiText is correct:
[regexp:created[]]

regex is wrong
201909[2

If you correct the regex:
201909[2]
you get the following error message:
Filter error: Syntax error in filter expression
This is a WikiText message with illogical content for someone who knows WikiText and RegEx.

In my opinion, this is really a bug.

@TiddlyTweeter
Copy link
Contributor

It is true.

TW uses those brackets internally.

My question was, and remains this: IN the CONTEXT of TW is it okay in its existing syntax to utilise [...] INSIDE filters that use [...] to hold them?

My concern is NOT function in regex. It is simply it may be CONFUSING breaking a general filter rule.

I'm actually neutral about the outcome.

@CarpeDiemKopi
Copy link
Author

Is there any (conceivable) use case at all that requires switching to WikiText within a RegEx?

@TiddlyTweeter
Copy link
Contributor

Is there any (conceivable) use case at all that requires switching to WikiText within a RegEx?

I have no idea what that means.

@pmario
Copy link
Contributor

pmario commented Sep 24, 2019

@CarpeDiemKopi this 201909(0[1-9]|1[0-5])) regexp is not valid.

Can you please specify what you want to achieve?

@pmario
Copy link
Contributor

pmario commented Sep 24, 2019

with a fixed syntax error, the mentioned reqexp is interpreted as:

// 201909(0[1-9]|1[0-5])
// 
// Match the characters “201909” literally «201909»
// Match the regular expression below and capture its match into backreference number 1 «(0[1-9]|1[0-5])»
//    Match either the regular expression below (attempting the next alternative only if this one fails) «0[1-9]»
//       Match the character “0” literally «0»
//       Match a single character in the range between “1” and “9” «[1-9]»
//    Or match regular expression number 2 below (the entire group fails if this one fails to match) «1[0-5]»
//       Match the character “1” literally «1»
//       Match a single character in the range between “0” and “5” «[0-5]»

@pmario
Copy link
Contributor

pmario commented Sep 24, 2019

TW can't handle "backreferences" at the moment!

@pmario
Copy link
Contributor

pmario commented Sep 24, 2019

If you can provide a valid regexp, it would be possible to check the problems.

@CarpeDiemKopi
Copy link
Author

@pmario
You probably copied the string from Jermolene's post. He added one parenthesis too many. The correct string is: 201909(0[1-9]|1[0-4]) from this thread: here is where it started
It should find all tiddlers created from 09/01/2019 inclusive to 09/15/2019 exclusive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants