bug #1772 [Store] Fix RstToctreeLoader trailing-slash toctree entry resolution (wachterjohannes)

This PR was merged into the main branch.

Discussion
----------

[Store] Fix RstToctreeLoader trailing-slash toctree entry resolution

  | Q             | A
  | ------------- | ---
  | Bug fix?      | yes
  | New feature?  | no
  | Docs?         | no
  | Issues        | Fix #1771
  | License       | MIT

## Summary

  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`.

Commits
-------

1bd2a72e [Store] Fix RstToctreeLoader trailing-slash toctree entry resolution
This commit is contained in:
Christopher Hertel
2026-03-15 22:00:09 +01:00
4 changed files with 29 additions and 0 deletions

View File

@@ -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';
}

View File

@@ -0,0 +1,4 @@
Components
==========
This section describes the available components.

View File

@@ -0,0 +1,9 @@
Main Index
==========
Welcome to the documentation.
.. toctree::
:hidden:
components/

View File

@@ -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();