Skip to content

Commit

Permalink
Fix regression of snippets nested deeply under specified base path (#…
Browse files Browse the repository at this point in the history
…2039)

Fixes #2038
  • Loading branch information
facelessuser committed May 16, 2023
1 parent 5e75073 commit 7c13bda
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 10.0.1

- **FIX**: Regression related to snippets nested deeply under specified base path.

## 10.0

- **Break**: Snippets: snippets will restrict snippets to ensure they are under the `base_path` preventing snippets
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(10, 0, 0, "final")
__version_info__ = Version(10, 0, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion pymdownx/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def get_snippet_path(self, path):
if self.restrict_base_path:
filename = os.path.abspath(os.path.join(base, path))
# If the absolute path is no longer under the specified base path, reject the file
if not os.path.samefile(base, os.path.dirname(filename)):
if not filename.startswith(base):
continue
else:
filename = os.path.join(base, path)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_extensions/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,34 @@ def test_restricted(self):
)


class TestSnippetsMultiNested(util.MdCase):
"""Test multi-nested restriction."""

extension = [
'pymdownx.snippets',
]

extension_configs = {
'pymdownx.snippets': {
'base_path': os.path.join(BASE),
'check_paths': True
}
}

def test_restricted_multi_nested(self):
"""Test file restriction."""

self.check_markdown(
R'''
--8<-- "_snippets/b.txt"
''',
'''
<p>Snippet</p>
''',
True
)


class TestSnippetsNestedUnrestricted(util.MdCase):
"""Test nested no bounds."""

Expand Down

0 comments on commit 7c13bda

Please sign in to comment.