View Issue Details

IDProjectCategoryView StatusLast Update
0037159FPCPackagespublic2020-06-08 23:42
ReporterCudaText man Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037159: TRegExpr patch from upstream
DescriptionPls sync with this fix

1-
https://github.com/andgineer/TRegExpr/commit/150b6e474eb626027b326f15ef23beefbed97b35
2 after it-
https://github.com/andgineer/TRegExpr/commit/309e80352e2288362d91da03301686e9df298bd4

Regexpr bug which is fixed-
https://github.com/andgineer/TRegExpr/issues/158
TagsNo tags attached.
Fixed in Revision45585.
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

Thaddy de Koning

2020-06-03 12:55

reporter   ~0123202

Last edited: 2020-06-03 12:56

View 2 revisions

I would prefer a patch over syncing. A patch can quickly be examined by eye.
So can you provide just the patch, and not request for syncing?
Because just probably not going to happen.

Michael Van Canneyt

2020-06-03 23:59

administrator   ~0123213

I agree with Thaddy.
If you provide a patch (you can easily create it with git diff) then things will go much faster.
If I must do it, it takes a longer time - I speak from experience.

Do-wan Kim

2020-06-04 13:57

reporter   ~0123218

37159_regexpr.pas.patch (2,359 bytes)   
Index: packages/regexpr/src/regexpr.pas
===================================================================
--- packages/regexpr/src/regexpr.pas	(revision 45584)
+++ packages/regexpr/src/regexpr.pas	(working copy)
@@ -2951,6 +2951,7 @@
   Len: integer;
   SavedPtr: PRegExprChar;
   EnderChar, TempChar: REChar;
+  DashForRange: Boolean;
 begin
   Result := nil;
   flags := 0;
@@ -3008,10 +3009,20 @@
 
         while (regparse < fRegexEnd) and (regparse^ <> ']') do
         begin
-          if (regparse^ = '-') and ((regparse + 1) < fRegexEnd) and
-            ((regparse + 1)^ <> ']') and CanBeRange then
+          // last '-' inside [] treated as simple dash
+          if (regparse^ = '-') and
+            ((regparse + 1) < fRegexEnd) and
+            ((regparse + 1)^ = ']') then
           begin
+            EmitRangeChar('-', False);
             Inc(regparse);
+            Break;
+          end;
+
+          // char '-' which (maybe) makes a range
+          if (regparse^ = '-') and ((regparse + 1) < fRegexEnd) and CanBeRange then
+          begin
+            Inc(regparse);
             RangeEnd := regparse^;
             if RangeEnd = EscChar then
             begin
@@ -3085,12 +3096,22 @@
               else
               begin
                 TempChar := UnQuoteChar(regparse);
-                EmitRangeChar(TempChar, (regparse + 1)^ = '-');
+                // False if '-' is last char in []
+                DashForRange :=
+                  (regparse + 2 < fRegexEnd) and
+                  ((regparse + 1)^ = '-') and
+                  ((regparse + 2)^ <> ']');
+                EmitRangeChar(TempChar, DashForRange);
               end;
             end
             else
             begin
-              EmitRangeChar(regparse^, (regparse + 1)^ = '-');
+              // False if '-' is last char in []
+              DashForRange :=
+                (regparse + 2 < fRegexEnd) and
+                ((regparse + 1)^ = '-') and
+                ((regparse + 2)^ <> ']');
+              EmitRangeChar(regparse^, DashForRange);
             end;
             Inc(regparse);
           end;
@@ -4468,7 +4489,7 @@
   end;
   SetLength(Result, ResultLen);
   // Fill Result
-  ResultPtr := Pointer(Result);
+  ResultPtr := PRegExprChar(Result);
   p := TemplateBeg;
   Mode := smodeNormal;
   while p < TemplateEnd do
37159_regexpr.pas.patch (2,359 bytes)   

Michael Van Canneyt

2020-06-04 15:34

administrator   ~0123219

@Kim: Thank you very much for the patch.

I applied it.

CudaText man

2020-06-08 21:05

reporter   ~0123343

Merge another my fix
https://github.com/andgineer/TRegExpr/pull/166

Michael Van Canneyt

2020-06-08 23:42

administrator   ~0123346

Applied in 45628.

but PLEASE provide a diff and PLEASE open a new report for different bugs.

Issue History

Date Modified Username Field Change
2020-06-01 13:21 CudaText man New Issue
2020-06-03 12:55 Thaddy de Koning Note Added: 0123202
2020-06-03 12:56 Thaddy de Koning Note Edited: 0123202 View Revisions
2020-06-03 23:57 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-06-03 23:57 Michael Van Canneyt Status new => assigned
2020-06-03 23:59 Michael Van Canneyt Note Added: 0123213
2020-06-04 13:57 Do-wan Kim Note Added: 0123218
2020-06-04 13:57 Do-wan Kim File Added: 37159_regexpr.pas.patch
2020-06-04 15:34 Michael Van Canneyt Status assigned => resolved
2020-06-04 15:34 Michael Van Canneyt Resolution open => fixed
2020-06-04 15:34 Michael Van Canneyt Fixed in Version => 3.3.1
2020-06-04 15:34 Michael Van Canneyt Fixed in Revision => 45585.
2020-06-04 15:34 Michael Van Canneyt FPCTarget => 4.0.0
2020-06-04 15:34 Michael Van Canneyt Note Added: 0123219
2020-06-08 21:05 CudaText man Status resolved => feedback
2020-06-08 21:05 CudaText man Resolution fixed => reopened
2020-06-08 21:05 CudaText man Note Added: 0123343
2020-06-08 23:42 Michael Van Canneyt Status feedback => resolved
2020-06-08 23:42 Michael Van Canneyt Note Added: 0123346
2020-06-08 23:42 Michael Van Canneyt Status resolved => closed
2020-06-08 23:42 Michael Van Canneyt Resolution reopened => fixed