Bug 165930 - F&R dialog accepts search patterns with text after $, should fail informatively
Summary: F&R dialog accepts search patterns with text after $, should fail informatively
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.4.7.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: needsDevEval
Depends on:
Blocks: Find&Replace-Dialog Find&Replace-Regex
  Show dependency treegraph
 
Reported: 2025-03-27 12:36 UTC by Eyal Rozenberg
Modified: 2025-12-03 14:05 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eyal Rozenberg 2025-03-27 12:36:35 UTC
At the moment, LO's regex capability does not include matching patterns across multiple paragraphs. Also, the $ character matches the end of a paragraph (not a line break or a line ending through wrapping).

Now, if in my document I have some text, then a paragraph break, then some more text, and I try a regex search with the pattern:

\.$\.

I expect to be told "Patterns with text beyond an end-of-paragraph marker $ are invalid." or "are not supported" etc.

Instead, I am told "Search key not found" - which suggests such patterns _are_ valid, and _might_ be matched, but the text doesn't have them.

Now, I would love it if support for past-end-of-paragraph were implemented, but while that's not happened - the user should be told that they can't do that.
Comment 1 V Stuart Foote 2025-03-28 14:32:39 UTC
+1 to clarify the "Search key not found" error when users enter invalid/unsupported regular expression(s).
Comment 2 Eyal Rozenberg 2025-03-31 08:20:07 UTC
Perhaps this would be an easyHack?
Comment 3 LeroyG 2025-11-27 15:46:52 UTC
(In reply to Eyal Rozenberg from comment #0)
> Instead, I am told "Search key not found" - which suggests such patterns
> _are_ valid, and _might_ be matched, but the text doesn't have them.

There are many patterns that are not supported. What about all of them?

I suggest not to use an specific message for each error, but to change the message (when [x] Regular expressions) something like: "Search key not found or invalid search pattern".

Reproducible with:

Version: 6.4.7.2 (x64)
Build ID: 639b8ac485750d5696d7590a72ef1b496725cfb5
CPU threads: 12; OS: Windows 10.0 Build 17763; UI render: GL; VCL: win; 
Locale: es-MX (es_AR); UI-Language: en-US
Calc: threaded
Comment 4 Eyal Rozenberg 2025-11-27 15:57:06 UTC
(In reply to LeroyG from comment #3)
> (In reply to Eyal Rozenberg from comment #0)
> > Instead, I am told "Search key not found" - which suggests such patterns
> > _are_ valid, and _might_ be matched, but the text doesn't have them.
> 
> There are many patterns that are not supported. What about all of them?

Well, all of them should result in an error message saying something like "Search pattern not supported" rather than "Search key not found" (or better yet, a brief text saying why the pattern is not supported.)

> I suggest not to use an specific message for each error, but to change the
> message (when [x] Regular expressions) something like: "Search key not found
> or invalid search pattern".

But we know which one of the two possibilities it was; no reason to obfuscate things for the user.
Comment 5 Heiko Tietze 2025-12-02 14:45:27 UTC
(In reply to LeroyG from comment #3)
> message (when [x] Regular expressions) something like: "Search key not found
> or invalid search pattern".
Sounds reasonable.

(In reply to Eyal Rozenberg from comment #4)
> But we know which one of the two possibilities it was...
Do we? Well in this case we can show a different message or even block the search.
Comment 6 Eyal Rozenberg 2025-12-02 19:17:34 UTC
(In reply to Heiko Tietze from comment #5)
> Do we?

I am 99% sure, that whatever library or facility we use to perform the pattern search distinguishes between an invalid search pattern and the case of no matches found. It's like that in sed, and grep, and JS functionality, and in PCRE you first compile and then match, etc. etc.

> Well in this case we can show a different message or even block the
> search.

That's basically what I meant.
Comment 7 Heiko Tietze 2025-12-03 05:55:13 UTC
(In reply to Eyal Rozenberg from comment #6)
> I am 99% sure...
I guess we do something like

while FindNext(*params)
{
  DoSomeMagic();
}
MessageBox("No more results");
Comment 8 Eyal Rozenberg 2025-12-03 14:05:13 UTC
(In reply to Heiko Tietze from comment #7)

Well, we're just guessing... I would guess it should be something like:

  needle = Compile(patterm);
  while FindNext(haystack_iterator, needle) {
    DoSomeMagic();
  }

but even if it's just like you described it, you can still probably do:

  if (not ValidPattern(*params); {
    HandleInvalidPattern(*params);
  }
  else while FindNext(*params)
  {
    DoSomeMagic();
  }

or:

  else while FindNext(*params)
  {
    DoSomeMagic();
  }
  status = GetFindState();
  if (status == PatternIsInvalid) {
    HandleInvalidPattern(*params);
  }