From 7de0e35a351cdf0a9a41fc8e644445f0d460346f Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 30 Aug 2022 17:48:38 -0500 Subject: [PATCH] Embed API: strip leading `/` before joining path (#9565) --- readthedocs/embed/v3/tests/test_internal_pages.py | 15 +++++++-------- readthedocs/embed/v3/views.py | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/readthedocs/embed/v3/tests/test_internal_pages.py b/readthedocs/embed/v3/tests/test_internal_pages.py index b1680b6a678..356b5769106 100644 --- a/readthedocs/embed/v3/tests/test_internal_pages.py +++ b/readthedocs/embed/v3/tests/test_internal_pages.py @@ -42,18 +42,17 @@ def f(*args, **kwargs): yield read_mock return f - def _patch_storage_open(self, storage_mock, content): - storage_mock.exists.return_value = True - storage_mock.open.side_effect = self._mock_open(content) - - @pytest.mark.sphinx('html', srcdir=srcdir, freshenv=True) - @mock.patch('readthedocs.embed.v3.views.build_media_storage') - def test_default_main_section(self, build_media_storage, app, client): + @pytest.mark.sphinx("html", srcdir=srcdir, freshenv=True) + @mock.patch("readthedocs.embed.v3.views.build_media_storage.open") + @mock.patch("readthedocs.embed.v3.views.build_media_storage.exists") + def test_default_main_section(self, storage_exists, storage_open, app, client): app.build() path = app.outdir / 'index.html' assert path.exists() is True content = open(path).read() - self._patch_storage_open(build_media_storage, content) + + storage_exists.return_value = True + storage_open.side_effect = self._mock_open(content) params = { 'url': 'https://project.readthedocs.io/en/latest/', diff --git a/readthedocs/embed/v3/views.py b/readthedocs/embed/v3/views.py index db5792f53e3..efd17e4b42e 100644 --- a/readthedocs/embed/v3/views.py +++ b/readthedocs/embed/v3/views.py @@ -90,9 +90,10 @@ def _get_page_content_from_storage(self, project, version_slug, filename): include_file=False, version_type=version.type, ) + relative_filename = filename.lstrip("/") file_path = build_media_storage.join( storage_path, - filename, + relative_filename, ) try: with build_media_storage.open(file_path) as fd: # pylint: disable=invalid-name