From 8a6381c3fa1ca150f6552f7d5fc08a2848cfcf85 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 1 Oct 2019 13:25:20 +0100 Subject: [PATCH 1/3] StupidJsonDecodeTest: add some extra test vectors --- tests/phpunit/network/mcpe/StupidJsonDecodeTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php b/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php index 8fced8a71..ac9940032 100644 --- a/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php +++ b/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php @@ -41,7 +41,9 @@ class StupidJsonDecodeTest extends TestCase{ ["NULL", null], ['["\",,\"word","a\",,\"word2",]', ['",,"word', 'a",,"word2', '']], ['["\",,\"word","a\",,\"word2",""]', ['",,"word', 'a",,"word2', '']], - ['["Hello,, PocketMine"]', ['Hello,, PocketMine']] + ['["Hello,, PocketMine"]', ['Hello,, PocketMine']], + ['[,]', ['', '']], + ['[]', []] ]; } From 4da06078edfe0cc69d1e9d98d85f401ce9b86dd8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 1 Oct 2019 14:22:07 +0100 Subject: [PATCH 2/3] Server: promote Patreon on startup --- src/pocketmine/Server.php | 1 + src/pocketmine/lang/locale | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 06497fde0..6a35a1a15 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2200,6 +2200,7 @@ class Server{ $this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [self::getGamemodeString($this->getGamemode())])); + $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) - \pocketmine\START_TIME, 3)])); $this->tickProcessor(); diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 73ed1ab3e..85343cfb7 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 73ed1ab3e1f2a1644fe908b439f8cf8ed6c12ab5 +Subproject commit 85343cfb7f7892bcb42ae7b7f594199cebca7d03 From 63d7e7b811d130fae663aa7cc517b04a32d37492 Mon Sep 17 00:00:00 2001 From: Dylan T Date: Tue, 1 Oct 2019 14:28:55 +0100 Subject: [PATCH 3/3] Fixed decoding form responses with double commas inside quotes (#3131) closes #3113 --- .../mcpe/PlayerNetworkSessionAdapter.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php index a3c8f9d65..7e546647c 100644 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php @@ -74,7 +74,6 @@ use function implode; use function json_decode; use function json_last_error_msg; use function preg_match; -use function preg_split; use function strlen; use function substr; use function trim; @@ -270,16 +269,31 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ */ 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 = "\"\""; + $raw = $matches[1]; + $lastComma = -1; + $newParts = []; + $quoteType = null; + 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){ throw new \InvalidArgumentException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)"); }