Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the edit_uri option does not modify the repo_url #2733

Merged
merged 3 commits into from Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions mkdocs/config/config_options.py
Expand Up @@ -354,12 +354,8 @@ def post_validation(self, config, key_name):
edit_uri = ''

# ensure a well-formed edit_uri
if edit_uri:
if not edit_uri.startswith(('?', '#')) \
and not config['repo_url'].endswith('/'):
config['repo_url'] += '/'
if not edit_uri.endswith('/'):
edit_uri += '/'
if edit_uri and not edit_uri.endswith('/'):
edit_uri += '/'

config['edit_uri'] = edit_uri

Expand Down
3 changes: 3 additions & 0 deletions mkdocs/structure/pages.py
Expand Up @@ -104,6 +104,9 @@ def _set_canonical_url(self, base):
def _set_edit_url(self, repo_url, edit_uri):
if repo_url and edit_uri:
src_path = self.file.src_path.replace('\\', '/')
# Ensure urljoin behavior is correct
if not edit_uri.startswith(('?', '#')) and not repo_url.endswith('/'):
repo_url += '/'
self.edit_url = urljoin(repo_url, edit_uri + src_path)
else:
self.edit_url = None
Expand Down
3 changes: 3 additions & 0 deletions mkdocs/tests/config/config_options_tests.py
Expand Up @@ -323,13 +323,15 @@ def test_edit_uri_github(self):
config = {'repo_url': "https://github.com/mkdocs/mkdocs"}
option.post_validation(config, 'repo_url')
self.assertEqual(config['edit_uri'], 'edit/master/docs/')
self.assertEqual(config['repo_url'], "https://github.com/mkdocs/mkdocs")

def test_edit_uri_bitbucket(self):

option = config_options.RepoURL()
config = {'repo_url': "https://bitbucket.org/gutworth/six/"}
option.post_validation(config, 'repo_url')
self.assertEqual(config['edit_uri'], 'src/default/docs/')
self.assertEqual(config['repo_url'], "https://bitbucket.org/gutworth/six/")

def test_edit_uri_gitlab(self):

Expand All @@ -344,6 +346,7 @@ def test_edit_uri_custom(self):
config = {'repo_url': "https://launchpad.net/python-tuskarclient"}
option.post_validation(config, 'repo_url')
self.assertEqual(config.get('edit_uri'), '')
self.assertEqual(config['repo_url'], "https://launchpad.net/python-tuskarclient")

def test_repo_name_custom_and_empty_edit_uri(self):

Expand Down