Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List converter for list of strings that contain comma aren't handled properly and result in a bad array #1301

Open
jbaranski opened this issue Oct 13, 2020 · 3 comments
Labels

Comments

@jbaranski
Copy link

jbaranski commented Oct 13, 2020

Describe the bug
fitnesse.slim.converters.ListConverterHelper::fromStringToArrayOfStrings for list of strings that contain comma aren't handled properly and result in a bad array.

To Reproduce
Steps to reproduce the behavior:

  1. Pass an array of string to the list converter (fitnesse.slim.converters.ListConverterHelper::fromStringToArrayOfStrings), if your array of string contains a comma, this results in a bad array.
  • For example, pass ["one,two,three"]. This is an array with length 1. After the list converter runs on it, we result in an array with length 3 ["\"one","two","three\""] which is not desired.

Expected behavior
Give a way to escape strings that contain a comma so our lists are preserved. Maybe there is some other kind of workaround?

Additional context
fitnesse.slim.converters.ListConverterHelper::fromStringToArrayOfStrings -- this strips the [ and ] then blindly splits on ,. Could this source code handle escaped commas before splitting?

@jbaranski jbaranski added the Bug label Oct 13, 2020
@fhoeben
Copy link
Collaborator

fhoeben commented Oct 13, 2020

As far as I know there's no way to escape a comma in this converter. (But in your example I expect you get an array with 3 elements "one, two and three", are the double quotes stripped from first and last element?)

Some time ago I created my own list fixture and list converter (and also a map fixture) since I found the default behaviour too limited. I did not see a way to change the default without breaking backward compatibility, unfortunately.

Sample usage of ListFixture at: https://raw.githubusercontent.com/fhoeben/hsac-fitnesse-fixtures/master/wiki/FitNesseRoot/HsacExamples/SlimTests/UtilityFixtures/ListFixtureTest.wiki

Sample usage of MapFixture: https://raw.githubusercontent.com/fhoeben/hsac-fitnesse-fixtures/master/wiki/FitNesseRoot/HsacExamples/SlimTests/UtilityFixtures/MapFixtureTest.wiki

@jbaranski
Copy link
Author

jbaranski commented Oct 13, 2020

Thanks, I'll take a look at your samples. Also there is a typo in my bug report, I updated it to reflect what really happens in the array, based on your double quotes comment (the double quotes don't magically line up like I had, was just trying to illustrate a simple case, I guess poorly 😊).

@jediwhale
Copy link
Collaborator

jediwhale commented Oct 21, 2020

I agree this code is broken but I'm not clear what it's used for. I've only worked on .NET Slim not Java Slim, but the Slim protocol describes lists and strings with colon-delimited length prefixes. From http://fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.SlimProtocol

Strings and Lists
As we will see, slim views a list as a special kind of string. Therefore functions can take and return lists as well as strings. The lists must be lists of strings, but since a list is a special kind of string, lists of lists of lists of ... are possible. The Slim executor will convert back and forth between these forms as needed.

A string is encoded as six or more digits followed by a colon, followed by the characters of the string. The six+ digits are the number of characters in the string, not including the digits themselves. Thus, the empty string is "000000:". This length encoding scheme is used in other places so we'll use the token to mean six digits followed by a colon.

If a string is null, then the four character string null will replace it.

A list is encoded as a string that begins with a '[', followed by a specifying the number of items in the list. This is followed by that many strings, each terminated by a colon, and then finally a ']' Thus, this list: [hello,world] is encoded as the following string:
000035:[000002:000005:hello:000005:world:]
Take careful note of all the colons and counts. Colons are terminators not separators.

As you can see, each item of a list is a string. But since a string can encode a list, each item of a list can be another list. So we can have very deep recursive definitions.

[0.4] For versions older than 0.4, the length part of an encoded string was exactly six digits. For version 0.4 the size can grow beyond 6 digits for really long messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants