diff --git a/src/Toml.php b/src/Toml.php index 27031f0..2b0e18f 100755 --- a/src/Toml.php +++ b/src/Toml.php @@ -102,6 +102,20 @@ public static function parse($toml) foreach($aTable as $i => $tableName) { + if($tableName == "") + { + // Empty table name + throw new Exception("Empty table keys aren't allowed on line " . $line); + } + + $tableName = trim($tableName); + + // Allow quoted table names + if($tableName[0] == '"' && substr($tableName,-1) == '"') + { + $tableName = json_decode($tableName); + } + if( !isset($pointer[$tableName]) ) { // Create array of tables @@ -137,6 +151,12 @@ public static function parse($toml) foreach($aTable as $i => $tableName) { + if($tableName == "") + { + // Empty table name + throw new Exception("Empty table keys aren't allowed on line " . $line); + } + if( !isset($pointer[$tableName]) ) { // Create table diff --git a/toml-test/debug.php b/toml-test/debug.php index da97630..0e1932d 100644 --- a/toml-test/debug.php +++ b/toml-test/debug.php @@ -2,7 +2,7 @@ require('../src/Toml.php'); -$toml = '["valid key"]'; +$toml = '[naughty..naughty]'; $result = Toml::parse($toml);