diff --git a/src/TomlKeystore.php b/src/TomlKeystore.php index 1b86cbe..44c3233 100644 --- a/src/TomlKeystore.php +++ b/src/TomlKeystore.php @@ -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'); } diff --git a/tests/Unit/TomlDecodeTest.php b/tests/Unit/TomlDecodeTest.php index e0060be..2eed11b 100644 --- a/tests/Unit/TomlDecodeTest.php +++ b/tests/Unit/TomlDecodeTest.php @@ -63,6 +63,11 @@ function () { { "name": "plantain" } ] } + ], + "fruit": [ + { + "name": "strawberry" + } ] } JSON_STRING; @@ -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)) diff --git a/tests/Unit/TomlErrorTest.php b/tests/Unit/TomlErrorTest.php index f8628c5..5dbdd05 100644 --- a/tests/Unit/TomlErrorTest.php +++ b/tests/Unit/TomlErrorTest.php @@ -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); + });