Skip to content

Commit

Permalink
Throw exception on invalid table names
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelquinteros committed Mar 27, 2015
1 parent 083c98a commit 3b57a3c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Toml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]) )
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3b57a3c

Please sign in to comment.