Skip to content

Commit

Permalink
Embed API: strip leading / before joining path (#9565)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Aug 30, 2022
1 parent eb11a4a commit 7de0e35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 7 additions & 8 deletions readthedocs/embed/v3/tests/test_internal_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/embed/v3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7de0e35

Please sign in to comment.