From 1bd2a72eb0a8c33b8ba6d2ca531188d8db8b50bd Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Sun, 15 Mar 2026 21:43:33 +0100 Subject: [PATCH] [Store] Fix RstToctreeLoader trailing-slash toctree entry resolution Trailing-slash toctree entries like `components/` are valid Sphinx syntax and resolve to `components/index.rst`. The loader now handles this convention instead of producing the invalid path `components/.rst`. --- src/store/src/Document/Loader/RstToctreeLoader.php | 2 ++ .../components/index.rst | 4 ++++ .../rst/with_trailing_slash_toctree/index.rst | 9 +++++++++ .../tests/Document/Loader/RstToctreeLoaderTest.php | 14 ++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst create mode 100644 src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst diff --git a/src/store/src/Document/Loader/RstToctreeLoader.php b/src/store/src/Document/Loader/RstToctreeLoader.php index 4a17f8ca..d14ce324 100644 --- a/src/store/src/Document/Loader/RstToctreeLoader.php +++ b/src/store/src/Document/Loader/RstToctreeLoader.php @@ -116,6 +116,8 @@ final class RstToctreeLoader implements LoaderInterface if (str_ends_with($entryPath, '.rst')) { $pattern = $dir.'/'.$entryPath; + } elseif (str_ends_with($entryPath, '/')) { + $pattern = $dir.'/'.$entryPath.'index.rst'; } else { $pattern = $dir.'/'.$entryPath.'.rst'; } diff --git a/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst new file mode 100644 index 00000000..8dfbbaa2 --- /dev/null +++ b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst @@ -0,0 +1,4 @@ +Components +========== + +This section describes the available components. diff --git a/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst new file mode 100644 index 00000000..6b4d2fb4 --- /dev/null +++ b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst @@ -0,0 +1,9 @@ +Main Index +========== + +Welcome to the documentation. + +.. toctree:: + :hidden: + + components/ diff --git a/src/store/tests/Document/Loader/RstToctreeLoaderTest.php b/src/store/tests/Document/Loader/RstToctreeLoaderTest.php index c91a50ab..4738e558 100644 --- a/src/store/tests/Document/Loader/RstToctreeLoaderTest.php +++ b/src/store/tests/Document/Loader/RstToctreeLoaderTest.php @@ -221,6 +221,20 @@ final class RstToctreeLoaderTest extends TestCase $this->assertCount(1, $alphaDocs); } + public function testLoadToctreeWithTrailingSlashResolvesToIndex() + { + $loader = new RstToctreeLoader(); + $documents = iterator_to_array($loader->load($this->fixturesDir.'/with_trailing_slash_toctree/index.rst'), false); + + $titles = array_map( + static fn (EmbeddableDocumentInterface $doc): string => $doc->getMetadata()->getTitle() ?? '', + $documents, + ); + + $this->assertContains('Main Index', $titles); + $this->assertContains('Components', $titles); + } + public function testLoadToctreeThrowsForMissingEntry() { $tempDir = sys_get_temp_dir().'/rst_missing_test_'.uniqid();