Skip to content

Commit

Permalink
Merge pull request #1060 from Paldari/bugfix/download-absolute-path
Browse files Browse the repository at this point in the history
Issue 1059: Fix downloadable abs path
  • Loading branch information
jdknight authored Nov 9, 2024
2 parents f6dcc89 + abb7ff9 commit 9655599
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
22 changes: 11 additions & 11 deletions sphinxcontrib/confluencebuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ def find_env_abspath(env, out_dir, path: str) -> Path | None:
# later stage
return None

if normalized_path.is_absolute():
abs_path = normalized_path
# some generated nodes will prefix the path of an asset with `/`,
# with the intent of that path being the root from the
# configured source directory instead of an absolute path on the
# system -- check the environment's source directory first before
# checking the full system's path
if normalized_path.parts[0] == os.sep:
abs_path = Path(env.srcdir, *normalized_path.parts[1:])

# some generated nodes will prefix the path of an asset with `/`,
# with the intent of that path being the root from the
# configured source directory instead of an absolute path on the
# system -- check the environment's source directory first before
# checking the full system's path
if normalized_path.name[0] == os.sep:
new_path = Path(env.srcdir, normalized_path.name[1:])
if abs_path.is_file():
return abs_path

if new_path.is_file():
abs_path = new_path
if normalized_path.is_absolute():
abs_path = normalized_path
else:
abs_path = Path(env.srcdir, normalized_path)

Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/unit-tests/datasets/download/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ download
:download:`../../assets/example.pdf`

:download:`label<../../assets/example.pdf>`

:download:`files/example.pdf`

.. Absolute filename taken as relative to the top source directory
:download:`/files/example.pdf`
26 changes: 16 additions & 10 deletions tests/unit-tests/test_sphinx_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ def test_storage_sphinx_download_defaults(self):
out_dir = self.build(self.dataset)

with parse('index', out_dir) as data:
# view-file
view_file_macro = data.find('ac:structured-macro',
# view-file(s)
#
# We have a couple of asset downloads in this example. A mixture
# of paths to sanity check download paths function. All use the
# same/replicated asset type and each will result in a single file
# upload, so we should have three matching view-file macros.
view_file_macros = data.find_all('ac:structured-macro',
{'ac:name': 'view-file'})
self.assertIsNotNone(view_file_macro)
self.assertEqual(len(view_file_macros), 3)

view_file_name = view_file_macro.find('ac:parameter',
{'ac:name': 'name'})
self.assertIsNotNone(view_file_name)
for view_file_macro in view_file_macros:
view_file_name = view_file_macro.find('ac:parameter',
{'ac:name': 'name'})
self.assertIsNotNone(view_file_name)

attachment_ref = view_file_name.find('ri:attachment')
self.assertIsNotNone(attachment_ref)
self.assertTrue(attachment_ref.has_attr('ri:filename'))
self.assertEqual(attachment_ref['ri:filename'], 'example.pdf')
attachment_ref = view_file_name.find('ri:attachment')
self.assertIsNotNone(attachment_ref)
self.assertTrue(attachment_ref.has_attr('ri:filename'))
self.assertEqual(attachment_ref['ri:filename'], 'example.pdf')

# link to file
file_link = data.find('ac:link')
Expand Down

0 comments on commit 9655599

Please sign in to comment.