diff --git a/src/pocketmine/utils/Config.php b/src/pocketmine/utils/Config.php index ec3185631..d10c885ac 100644 --- a/src/pocketmine/utils/Config.php +++ b/src/pocketmine/utils/Config.php @@ -111,7 +111,7 @@ class Config{ * @return string */ public static function fixYAMLIndexes(string $str) : string{ - return preg_replace("#^([ ]*)([a-zA-Z_]{1}[ ]*)\\:$#m", "$1\"$2\":", $str); + return preg_replace("#^( *)(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)( *)\:#m", "$1\"$2\"$3:", $str); } /** diff --git a/tests/phpunit/utils/ConfigTest.php b/tests/phpunit/utils/ConfigTest.php new file mode 100644 index 000000000..7c48562ec --- /dev/null +++ b/tests/phpunit/utils/ConfigTest.php @@ -0,0 +1,71 @@ + 1, + "y" => 2, + "z" => 3 + ]]; + yield [" x : 1\n y : 2\n z : 3\n", [ + "x" => 1, + "y" => 2, + "z" => 3 + ]]; + yield ["parent:\n x: 1\n y: 2\n z: 3\n", [ + "parent" => [ + "x" => 1, + "y" => 2, + "z" => 3 + ] + ]]; + yield ["yes: notransform", [ + "yes" => "notransform" + ]]; + yield ["on: 1\nyes: true", [ //this would previously have resulted in a key collision + "on" => 1, + "yes" => true + ]]; + } + + /** + * @dataProvider fixYamlIndexesProvider + * + * @param string $test + * @param array $expected + */ + public function testFixYamlIndexes(string $test, array $expected) : void{ + $fixed = Config::fixYAMLIndexes($test); + $decoded = yaml_parse($fixed); + self::assertEquals($expected, $decoded); + } +}