View Issue Details

IDProjectCategoryView StatusLast Update
0017532LazarusIDEpublic2010-10-07 14:51
ReporterSergei GorelkinAssigned ToMaxim Ganetsky 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.29 (SVN)Product Build 
Target VersionFixed in Version0.9.29 (SVN) 
Summary0017532: "Find in files" search for a regular expression is incorrect
DescriptionTrying to search files for a regular expression produces incorrect results.
As an example:

- Open 'Find in files' dialog
- Enter '\sEDOM' (without quotes) as a search expression
- Check 'regular expressions' checkbox
- Select 'Find in directories' and enter path to ...\trunk\packages in FPC source tree.
- Enter standard '*.pas;*.pp;*inc' as a file mask.
- Check the 'search in subdirectories' checkbox.

It will find a lot of matches, matching 'EDOM' with one or two characters preceding, but it will never match 'EDOM' with preceding whitespace (which is the expected result).

At the same time, searching '\sEDOM' regular expression in a single file (in my case, it is trunk\packages\fcl-xml\src\dom.pp) with 'Search->Find' command works correctly.
TagsNo tags attached.
Fixed in Revision27591
LazTarget-
Widgetset
Attached Files
  • RegEx2_r27585.patch (1,760 bytes)
    Index: ide/searchfrm.pas
    ===================================================================
    --- ide/searchfrm.pas	(revision 27584)
    +++ ide/searchfrm.pas	(working copy)
    @@ -515,34 +515,26 @@
           OriginalFile:=TSourceLog.Create(TheText);
         end;
     
    -    // convert case
    -    if sesoMatchCase in Flags then begin
    -      CaseFile:=OriginalFile;
    -    end else begin
    -      CaseFile:=TSourceLog.Create(UpperCaseStr(OriginalFile.Source));
    -      TempSearch:=UpperCaseStr(TempSearch);
    -    end;
    +    // assigning for cleanup at the end
    +    CaseFile:=OriginalFile;
     
         if sesoRegExpr in Flags then begin
           // Setup the regular expression search engine
           RE:=TRegExpr.Create;
    -      RE.ModifierI:=(sesoReplace in Flags) and (not (sesoMatchCase in Flags));
    +      RE.ModifierI:=not (sesoMatchCase in Flags);
           RE.ModifierM:=true;
           RE.ModifierS:=sesoMultiLine in Flags;
    -      if (sesoReplace in Flags) then begin
    -        Src:=OriginalFile.Source;
    -        if sesoWholeWord in Flags then
    -          RE.Expression:= '\b'+SearchFor+'\b'
    -        else
    -          RE.Expression:= SearchFor;
    -      end else begin
    -        Src:=CaseFile.Source;
    -        if sesoWholeWord in Flags then
    -          RE.Expression:= '\b'+TempSearch+'\b'
    -        else
    -          RE.Expression:= TempSearch;
    -      end;
    +      Src:=OriginalFile.Source;
    +      if sesoWholeWord in Flags then
    +        RE.Expression:= '\b'+SearchFor+'\b'
    +      else
    +        RE.Expression:= SearchFor;
         end else begin
    +      // convert case if necessary
    +      if not (sesoMatchCase in Flags) then begin
    +        CaseFile:=TSourceLog.Create(UpperCaseStr(OriginalFile.Source));
    +        TempSearch:=UpperCaseStr(TempSearch);
    +      end;
           Src:=CaseFile.Source;
         end;
     
    
    RegEx2_r27585.patch (1,760 bytes)

Activities

Sergei Gorelkin

2010-10-03 15:34

reporter   ~0041442

It looks that using case-insensitive search in combination with regular expression erroneously converts search pattern '\sEDOM' into all-uppercase '\SEDOM', which changes the meaning of the first character.

I still can't figure out why this happens only with 'Find in files' command, but not with 'Find'.

Maxim Ganetsky

2010-10-06 00:51

developer   ~0041532

I propose attached patch. It appears to work but should be carefully tested for regressions and reviewed.

2010-10-06 02:23

 

RegEx2_r27585.patch (1,760 bytes)
Index: ide/searchfrm.pas
===================================================================
--- ide/searchfrm.pas	(revision 27584)
+++ ide/searchfrm.pas	(working copy)
@@ -515,34 +515,26 @@
       OriginalFile:=TSourceLog.Create(TheText);
     end;
 
-    // convert case
-    if sesoMatchCase in Flags then begin
-      CaseFile:=OriginalFile;
-    end else begin
-      CaseFile:=TSourceLog.Create(UpperCaseStr(OriginalFile.Source));
-      TempSearch:=UpperCaseStr(TempSearch);
-    end;
+    // assigning for cleanup at the end
+    CaseFile:=OriginalFile;
 
     if sesoRegExpr in Flags then begin
       // Setup the regular expression search engine
       RE:=TRegExpr.Create;
-      RE.ModifierI:=(sesoReplace in Flags) and (not (sesoMatchCase in Flags));
+      RE.ModifierI:=not (sesoMatchCase in Flags);
       RE.ModifierM:=true;
       RE.ModifierS:=sesoMultiLine in Flags;
-      if (sesoReplace in Flags) then begin
-        Src:=OriginalFile.Source;
-        if sesoWholeWord in Flags then
-          RE.Expression:= '\b'+SearchFor+'\b'
-        else
-          RE.Expression:= SearchFor;
-      end else begin
-        Src:=CaseFile.Source;
-        if sesoWholeWord in Flags then
-          RE.Expression:= '\b'+TempSearch+'\b'
-        else
-          RE.Expression:= TempSearch;
-      end;
+      Src:=OriginalFile.Source;
+      if sesoWholeWord in Flags then
+        RE.Expression:= '\b'+SearchFor+'\b'
+      else
+        RE.Expression:= SearchFor;
     end else begin
+      // convert case if necessary
+      if not (sesoMatchCase in Flags) then begin
+        CaseFile:=TSourceLog.Create(UpperCaseStr(OriginalFile.Source));
+        TempSearch:=UpperCaseStr(TempSearch);
+      end;
       Src:=CaseFile.Source;
     end;
 
RegEx2_r27585.patch (1,760 bytes)

Maxim Ganetsky

2010-10-06 22:13

developer   ~0041556

Please test and close if OK.

Issue History

Date Modified Username Field Change
2010-10-02 13:07 Sergei Gorelkin New Issue
2010-10-02 13:07 Sergei Gorelkin Widgetset => Win32/Win64
2010-10-03 15:34 Sergei Gorelkin Note Added: 0041442
2010-10-06 00:50 Maxim Ganetsky File Added: RegEx_r27585.patch
2010-10-06 00:51 Maxim Ganetsky Note Added: 0041532
2010-10-06 00:52 Maxim Ganetsky LazTarget => -
2010-10-06 00:52 Maxim Ganetsky Status new => confirmed
2010-10-06 02:23 Maxim Ganetsky File Added: RegEx2_r27585.patch
2010-10-06 02:23 Maxim Ganetsky File Deleted: RegEx_r27585.patch
2010-10-06 22:13 Maxim Ganetsky Fixed in Revision => 27591
2010-10-06 22:13 Maxim Ganetsky Widgetset Win32/Win64 =>
2010-10-06 22:13 Maxim Ganetsky Status confirmed => resolved
2010-10-06 22:13 Maxim Ganetsky Fixed in Version => 0.9.29 (SVN)
2010-10-06 22:13 Maxim Ganetsky Resolution open => fixed
2010-10-06 22:13 Maxim Ganetsky Assigned To => Maxim Ganetsky
2010-10-06 22:13 Maxim Ganetsky Note Added: 0041556
2010-10-07 14:51 Sergei Gorelkin Status resolved => closed