-
Notifications
You must be signed in to change notification settings - Fork 0
StringUtil#splitOnEverySecondWhiteSpace returns empty collection when string with no whitespace is passed as argument. #1
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
This bug causes functions which use it to act how they should not.
String parsing function:
@NotNull
public static List<@NotNull String> splitOnEverySecondWhiteSpace(@NotNull String args)
{
String regex = "(\\S+\\s+\\S+)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(args);
List<String> result = new ArrayList<>();
while (matcher.find())
{
result.add(matcher.group());
}
return result;
}For example, when parsing arguments in:
@Override
@NotNull
public Map<String, @Nullable String> parse(@NotNull String args, @NotNull String keyValueDelimiter)
{
Map<String, @Nullable String> result = new HashMap<>();
List<String> pairs = StringUtil.splitOnEverySecondWhiteSpace(args);
List<String> validKeys = Arrays.asList(keys);
for (String pair : pairs)
{
String[] keyValue = pair.split(keyValueDelimiter);
if (keyValue.length != 2 || keyValue[1].isEmpty())
{
throw new IllegalArgumentException("Missing value for key: " + keyValue[0]);
}
if (!validKeys.contains(keyValue[0]))
{
System.out.println("Unrecognized key: " + keyValue[0]);
return new HashMap<>();
}
result.put(keyValue[0], keyValue[1]);
}
return result;
}If we enter in console:
kappa> cc -fn
expected output should be:
kappa> cc -fn
Missing value for '-fn' key
but actual is
Failed to parse arguments
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working