View Issue Details

IDProjectCategoryView StatusLast Update
0036806FPCRTLpublic2020-03-19 22:42
ReporterdelfionAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.3.1Product Build44086 
Target VersionFixed in Version3.3.1 
Summary0036806: Stringhelper.Split returns array with extra empty string when last char of the string is delimiter.
Descriptionwriteln(length('a'0000010'b'0000010.Split(0000010,TStringSplitOptions.ExcludeEmpty)));
prints 3 when expected is 2.

Patch attached.
TagsNo tags attached.
Fixed in Revision44313
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • split.diff (603 bytes)
    Index: rtl/objpas/sysutils/syshelp.inc
    ===================================================================
    --- rtl/objpas/sysutils/syshelp.inc	(revision 44086)
    +++ rtl/objpas/sysutils/syshelp.inc	(working copy)
    @@ -1225,9 +1225,12 @@
         begin
         T:=SubString(LastSep);
     //    Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
    -    MaybeGrow(Len);
    -    Result[Len]:=T;
    -    Inc(Len);
    +    If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
    +      begin
    +      MaybeGrow(Len);
    +      Result[Len]:=T;
    +      Inc(Len);
    +      end;
         end;
       SetLength(Result,Len);
     end;
    
    split.diff (603 bytes)
  • split2.diff (603 bytes)
    Index: rtl/objpas/sysutils/syshelp.inc
    ===================================================================
    --- rtl/objpas/sysutils/syshelp.inc	(revision 44086)
    +++ rtl/objpas/sysutils/syshelp.inc	(working copy)
    @@ -1311,9 +1311,12 @@
         begin
         T:=SubString(LastSep);
     //    Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
    -    MaybeGrow(Len);
    -    Result[Len]:=T;
    -    Inc(Len);
    +    If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
    +      begin
    +      MaybeGrow(Len);
    +      Result[Len]:=T;
    +      Inc(Len);
    +      end;
         end;
       SetLength(Result,Len);
     end;
    
    split2.diff (603 bytes)

Activities

delfion

2020-03-19 13:38

reporter  

split.diff (603 bytes)
Index: rtl/objpas/sysutils/syshelp.inc
===================================================================
--- rtl/objpas/sysutils/syshelp.inc	(revision 44086)
+++ rtl/objpas/sysutils/syshelp.inc	(working copy)
@@ -1225,9 +1225,12 @@
     begin
     T:=SubString(LastSep);
 //    Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
-    MaybeGrow(Len);
-    Result[Len]:=T;
-    Inc(Len);
+    If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
+      begin
+      MaybeGrow(Len);
+      Result[Len]:=T;
+      Inc(Len);
+      end;
     end;
   SetLength(Result,Len);
 end;
split.diff (603 bytes)

Michael Van Canneyt

2020-03-19 14:48

administrator   ~0121650

Fixed, thank you for the patch.

delfion

2020-03-19 20:43

reporter   ~0121651

Overloaded version of split needs same cure

delfion

2020-03-19 20:44

reporter  

split2.diff (603 bytes)
Index: rtl/objpas/sysutils/syshelp.inc
===================================================================
--- rtl/objpas/sysutils/syshelp.inc	(revision 44086)
+++ rtl/objpas/sysutils/syshelp.inc	(working copy)
@@ -1311,9 +1311,12 @@
     begin
     T:=SubString(LastSep);
 //    Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
-    MaybeGrow(Len);
-    Result[Len]:=T;
-    Inc(Len);
+    If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
+      begin
+      MaybeGrow(Len);
+      Result[Len]:=T;
+      Inc(Len);
+      end;
     end;
   SetLength(Result,Len);
 end;
split2.diff (603 bytes)

Michael Van Canneyt

2020-03-19 22:42

administrator   ~0121653

Applied, thanks.

Issue History

Date Modified Username Field Change
2020-03-19 13:38 delfion New Issue
2020-03-19 13:38 delfion File Added: split.diff
2020-03-19 14:48 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-03-19 14:48 Michael Van Canneyt Status new => resolved
2020-03-19 14:48 Michael Van Canneyt Resolution open => fixed
2020-03-19 14:48 Michael Van Canneyt Fixed in Version => 3.3.1
2020-03-19 14:48 Michael Van Canneyt Fixed in Revision => 44312
2020-03-19 14:48 Michael Van Canneyt FPCTarget => 3.2.0
2020-03-19 14:48 Michael Van Canneyt Note Added: 0121650
2020-03-19 20:43 delfion Status resolved => feedback
2020-03-19 20:43 delfion Resolution fixed => reopened
2020-03-19 20:43 delfion Note Added: 0121651
2020-03-19 20:44 delfion File Added: split2.diff
2020-03-19 22:42 Michael Van Canneyt Status feedback => resolved
2020-03-19 22:42 Michael Van Canneyt Fixed in Revision 44312 => 44313
2020-03-19 22:42 Michael Van Canneyt Note Added: 0121653
2020-03-19 22:42 Michael Van Canneyt Resolution reopened => fixed
2020-03-19 22:42 Michael Van Canneyt Description Updated View Revisions