Merge branch 'release/3.2'

This commit is contained in:
Dylan K. Taylor
2018-08-19 10:37:20 +01:00
2 changed files with 87 additions and 1 deletions

View File

@ -391,7 +391,37 @@ class SimpleSessionHandler extends SessionHandler{
}
public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{
return $this->player->onFormSubmit($packet->formId, json_decode($packet->formData, true));
return $this->player->onFormSubmit($packet->formId, self::stupid_json_decode($packet->formData, true));
}
/**
* Hack to work around a stupid bug in Minecraft W10 which causes empty strings to be sent unquoted in form responses.
*
* @param string $json
* @param bool $assoc
*
* @return mixed
*/
private static function stupid_json_decode(string $json, bool $assoc = false){
if(preg_match('/^\[(.+)\]$/s', $json, $matches) > 0){
$parts = preg_split('/(?:"(?:\\"|[^"])*"|)\K(,)/', $matches[1]); //Splits on commas not inside quotes, ignoring escaped quotes
foreach($parts as $k => $part){
$part = trim($part);
if($part === ""){
$part = "\"\"";
}
$parts[$k] = $part;
}
$fixed = "[" . implode(",", $parts) . "]";
if(($ret = json_decode($fixed, $assoc)) === null){
throw new \InvalidArgumentException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)");
}
return $ret;
}
return json_decode($json, $assoc);
}
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{