mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Merge remote-tracking branch 'origin/stable'
This commit is contained in:
commit
464b2116a6
@ -1 +1 @@
|
|||||||
Subproject commit 8718542e622014fa81e6c178a3c83202c86ef921
|
Subproject commit 157abfa5a2ae85325fb254ec3ca19373116bb6af
|
@ -1286,7 +1286,7 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [$this->getGamemode()->getTranslationKey()]));
|
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [$this->getGamemode()->getTranslationKey()]));
|
||||||
|
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.donate", [TextFormat::AQUA . "https://patreon.com/pocketminemp" . TextFormat::RESET]));
|
||||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.startFinished", [round(microtime(true) - $this->startTime, 3)]));
|
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.startFinished", [round(microtime(true) - $this->startTime, 3)]));
|
||||||
|
|
||||||
//TODO: move console parts to a separate component
|
//TODO: move console parts to a separate component
|
||||||
|
@ -91,8 +91,9 @@ use function json_encode;
|
|||||||
use function json_last_error_msg;
|
use function json_last_error_msg;
|
||||||
use function microtime;
|
use function microtime;
|
||||||
use function preg_match;
|
use function preg_match;
|
||||||
use function preg_split;
|
use function strlen;
|
||||||
use function strpos;
|
use function strpos;
|
||||||
|
use function substr;
|
||||||
use function trim;
|
use function trim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -674,18 +675,33 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
*/
|
*/
|
||||||
private static function stupid_json_decode(string $json, bool $assoc = false){
|
private static function stupid_json_decode(string $json, bool $assoc = false){
|
||||||
if(preg_match('/^\[(.+)\]$/s', $json, $matches) > 0){
|
if(preg_match('/^\[(.+)\]$/s', $json, $matches) > 0){
|
||||||
$parts = preg_split('/(?:"(?:\\"|[^"])*"|)\K(,)/', $matches[1]); //Splits on commas not inside quotes, ignoring escaped quotes
|
$raw = $matches[1];
|
||||||
foreach($parts as $k => $part){
|
$lastComma = -1;
|
||||||
$part = trim($part);
|
$newParts = [];
|
||||||
if($part === ""){
|
$quoteType = null;
|
||||||
$part = "\"\"";
|
for($i = 0, $len = strlen($raw); $i <= $len; ++$i){
|
||||||
|
if($i === $len or ($raw[$i] === "," and $quoteType === null)){
|
||||||
|
$part = substr($raw, $lastComma + 1, $i - ($lastComma + 1));
|
||||||
|
if(trim($part) === ""){ //regular parts will have quotes or something else that makes them non-empty
|
||||||
|
$part = '""';
|
||||||
|
}
|
||||||
|
$newParts[] = $part;
|
||||||
|
$lastComma = $i;
|
||||||
|
}elseif($raw[$i] === '"'){
|
||||||
|
if($quoteType === null){
|
||||||
|
$quoteType = $raw[$i];
|
||||||
|
}elseif($raw[$i] === $quoteType){
|
||||||
|
for($backslashes = 0; $backslashes < $i && $raw[$i - $backslashes - 1] === "\\"; ++$backslashes){}
|
||||||
|
if(($backslashes % 2) === 0){ //unescaped quote
|
||||||
|
$quoteType = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$parts[$k] = $part;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fixed = "[" . implode(",", $parts) . "]";
|
$fixed = "[" . implode(",", $newParts) . "]";
|
||||||
if(($ret = json_decode($fixed, $assoc)) === null){
|
if(($ret = json_decode($fixed, $assoc)) === null){
|
||||||
throw new BadPacketException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)");
|
throw new \InvalidArgumentException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
@ -41,7 +41,9 @@ class StupidJsonDecodeTest extends TestCase{
|
|||||||
["NULL", null],
|
["NULL", null],
|
||||||
['["\",,\"word","a\",,\"word2",]', ['",,"word', 'a",,"word2', '']],
|
['["\",,\"word","a\",,\"word2",]', ['",,"word', 'a",,"word2', '']],
|
||||||
['["\",,\"word","a\",,\"word2",""]', ['",,"word', 'a",,"word2', '']],
|
['["\",,\"word","a\",,\"word2",""]', ['",,"word', 'a",,"word2', '']],
|
||||||
['["Hello,, PocketMine"]', ['Hello,, PocketMine']]
|
['["Hello,, PocketMine"]', ['Hello,, PocketMine']],
|
||||||
|
['[,]', ['', '']],
|
||||||
|
['[]', []]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user