So I was curious about this so I took a look myself.
Congratulations, you have found a bug in Minecraft. In particular the brigadier system. At least as far as I can trace it (I havent decompiled anything). This is as far as I got.
Anyway solutions. First I would report it to MC. But as for a solution.
using remainingJoinedStrings does bypass the issue. Not ideal
using a custom parser that runs remaining. Also not ideal. But you maybe able to set the cursor to the end of the word. If so the rest of the command system should work normally from that point
Edit:
playing around with the second option, I think I have found a solution. This is my custom parser
.addParser((parameterKey, reader, context) -> {
String remaining = reader.remaining();
int index = remaining.indexOf(" ");
if (index == -1 && remaining.isEmpty()) { //If no data was entered then reject
return Optional.empty();
} else if (index == -1) {
index = remaining.length(); //If no more arguments left, then this is the last
}
String result = remaining.substring(0, index); //gets the word
//this moves the cursor over the word
for (int i = 0; i < result.length(); i++) {
reader.parseChar();
//reader.skipWhitespace(); <--- this doesn't do what I expected which was to move the cursor over by one so I used parseChar to replicate that
}
return Optional.of(result);
})