From 3b57a3c42a654fcfd425c740f98ad2bdc348e4fa Mon Sep 17 00:00:00 2001 From: Leonel Quinteros Date: Fri, 27 Mar 2015 20:32:03 -0300 Subject: [PATCH] Throw exception on invalid table names --- src/Toml.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Toml.php b/src/Toml.php index 2b0e18f..72d77c9 100755 --- a/src/Toml.php +++ b/src/Toml.php @@ -105,7 +105,7 @@ public static function parse($toml) if($tableName == "") { // Empty table name - throw new Exception("Empty table keys aren't allowed on line " . $line); + throw new Exception("Empty table keys aren't allowed"); } $tableName = trim($tableName); @@ -115,6 +115,11 @@ public static function parse($toml) { $tableName = json_decode($tableName); } + elseif(!ctype_alnum(str_replace(array('-', '_', '.'), '', $tableName))) // Check for proper keys + { + // Invalid table name + throw new Exception("Invalid table name: " . $tableName); + } if( !isset($pointer[$tableName]) ) { @@ -145,6 +150,11 @@ public static function parse($toml) { $tableName = json_decode($tableName); } + elseif(!ctype_alnum(str_replace(array('-', '_', '.'), '', $tableName))) // Check for proper keys + { + // Invalid table name + throw new Exception("Invalid table name: " . $tableName); + } $aTable = explode('.', $tableName); $last = count($aTable) - 1;