Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TomlKeystore.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function addArrayTableNode(ArrayTableNode $arrayTableNode): void
}

if ($index === 0 && ! $this->tables->filter(
static fn ($table) => str_starts_with((string) $table, $header))->isEmpty()
static fn ($table) => str_starts_with((string) $table, $header . "."))->isEmpty()
) {
throw new TomlError('key duplication');
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/TomlDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function () {
{ "name": "plantain" }
]
}
],
"fruit": [
{
"name": "strawberry"
}
]
}
JSON_STRING;
Expand Down Expand Up @@ -111,6 +116,9 @@ function () {

[[fruits.varieties]]
name = "plantain"

[[fruit]] # prefix of existing array
name = "strawberry"
TOML_STRING;

expect(toml_decode($toml))->toEqual(json_decode($json, false))
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/TomlErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,31 @@ function () {

expect(static fn () => toml_decode($toml, true))->toThrow(TomlError::class, $message);
});

it('throws on invalid array order',
/**
* @throws TomlError
*/
function () {

$message = <<<'MESSAGE'
Invalid TOML document: key duplication

5: # This requires a to be an array table
6: [[a]]
^
7: y = 2
MESSAGE;

$toml = <<<'TOML_STRING'
# This creates a as a normal (non-array) table
[[a.b]]
x = 1

# This requires a to be an array table
[[a]]
y = 2
TOML_STRING;

expect(static fn () => toml_decode($toml, true))->toThrow(TomlError::class, $message);
});