`Text.Join` bug

Feedback Case: <https://xojo.com/issue/65508>

Following on from the discussion on this thread where @Geoff_Perlman as good as recommended I switch to using Text from String for the code editor I’m working on, I have hit what looks to be a nasty bug in the (now deprecated) Text class. I’m posting the essence of the Feedback case here in the hope that an engineer might notice it sooner. I’m also hoping that there’s a chance it can be fixed even though Text is deprecated.

Put this in Window.Open:

// Create a Text array that contains an empty Text row.
Var t() As Text
t.Add("{")
t.Add("")
t.Add("}")

// Concatenate with the UNIX line ending.
// The output should be:
//  {
//
//  }
// It's correct on macOS but on Windows & Linux you get:
// {
// }

Var concat As Text = Text.Join(t, &u0A)

If concat <> "{" + &u0A + &u0A + "}" Then
  Raise New RuntimeException("Works on macOS, fails on Win/Linux")
End If

There is a workaround for Linux & Windows but it’s pig slow:

Function ProperlyJoin(items As Text, separator As Text) As Text
#If TargetMacOS
  // Use `Text.Join` since it works on macOS.
  Return Text.Join(items, separator)
#Else
  If items.Count = 0 Then Return ""
  Var t As Text
  Var iMax As Integer = items.LastIndex
  For i As Integer = 0 To iMax
    t = t + items(i)
    If i < iMax Then t = t + separator
  Next i
  Return t
#EndIf
End Function

In the debugger, there is simply no character there? And could you substitute a space instead of an empty string to get around the issue?

Finally, what about using a String array and converting to Text after the Join?

Correct. It seems like the Join method doesn’t see the empty row in the array.

A good suggestion but for complex reasons, the array is always Text (since everything textual in the editor is stored as Text). The editor essentially stores every line of text as a row in a Text array.

Unfortunately not. I can’t control the input Text array as it’s code entered by the user. Typically an empty row in the array would represent a blank line.

The concern here is the difference in behaviour between macOS and Windows / Linux. I suspect it relates to the underlying ICU library used by the Xojo framework on Linux / Windows.

I doubt it. It’s an universal library extensively tested. Probably just another Xojo wrapping bug. We had one platform misbehavior another day working for Windows and Mac but not Linux, the issue was because Xojo updated their wrapper for both but postponed the Linux one (using a static lib linked into the framework if I do recall correctly). Probably just a Xojo platform issue.

And yes, the Text.Join() for Windows is ignoring empty strings. This is the bug. Please file a Bug Report. And Xojo, please make a test case and run on each supported platform.

Looks like @William_Yu has marked this as fixed. Amazing. Thanks!