Skip to content

Commit

Permalink
Improve table name parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelquinteros committed Mar 27, 2015
1 parent cb55cb8 commit 083c98a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Toml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion toml-test/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require('../src/Toml.php');

$toml = '["valid key"]';
$toml = '[naughty..naughty]';

$result = Toml::parse($toml);

Expand Down

0 comments on commit 083c98a

Please sign in to comment.