ConsoleReaderThread: strip control characters

this fixes a bug I encountered when accidentally pressing ctrl+a+d (which inserts a chr(1) character), because it made the server unable to find the command - but still reported an error containing what looked like a valid command (character isn't printable).
This commit is contained in:
Dylan K. Taylor 2021-11-02 15:11:10 +00:00
parent ede4157814
commit 4dc13ab3da
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -114,7 +114,9 @@ final class ConsoleReaderThread extends Thread{
break;
}
$buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($command));
$command = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($command)) ?? throw new AssumptionFailedError("This regex is assumed to be valid");
$command = preg_replace('/[[:cntrl:]]/', '', $command) ?? throw new AssumptionFailedError("This regex is assumed to be valid");
$buffer[] = $command;
if($notifier !== null){
$notifier->wakeupSleeper();
}