Use regex for command argument parsing, fixes #2266

moral of the story: don't abuse functions for things they weren't designed for... lol
This commit is contained in:
Dylan K. Taylor 2019-02-14 15:07:58 +00:00
parent c433fad0a7
commit c346c45d42

View File

@ -66,13 +66,13 @@ use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand; use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\Server; use pocketmine\Server;
use function array_map;
use function array_shift; use function array_shift;
use function count; use function count;
use function explode; use function explode;
use function implode; use function implode;
use function min; use function min;
use function str_getcsv; use function preg_match_all;
use function stripslashes;
use function strpos; use function strpos;
use function strtolower; use function strtolower;
use function trim; use function trim;
@ -247,7 +247,16 @@ class SimpleCommandMap implements CommandMap{
} }
public function dispatch(CommandSender $sender, string $commandLine) : bool{ public function dispatch(CommandSender $sender, string $commandLine) : bool{
$args = array_map("\stripslashes", str_getcsv($commandLine, " ")); $args = [];
preg_match_all('/"((?:\\\\.|[^\\\\"])*)"|(\S+)/u', $commandLine, $matches);
foreach($matches[0] as $k => $_){
for($i = 1; $i <= 2; ++$i){
if($matches[$i][$k] !== ""){
$args[$k] = stripslashes($matches[$i][$k]);
break;
}
}
}
$sentCommandLabel = ""; $sentCommandLabel = "";
$target = $this->matchCommand($sentCommandLabel, $args); $target = $this->matchCommand($sentCommandLabel, $args);