From 10aecb98c6d57b143a7c9f3e3aa2657aa830540c Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Wed, 29 Dec 2021 11:03:41 -0500 Subject: [PATCH 1/2] Ensure that the `edit_uri` option does not modify the `repo_url` --- mkdocs/config/config_options.py | 8 ++------ mkdocs/structure/pages.py | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py index 8caf16ad5e..f9437cf4a5 100644 --- a/mkdocs/config/config_options.py +++ b/mkdocs/config/config_options.py @@ -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 diff --git a/mkdocs/structure/pages.py b/mkdocs/structure/pages.py index b993ae24fb..f1e71e26bf 100644 --- a/mkdocs/structure/pages.py +++ b/mkdocs/structure/pages.py @@ -107,6 +107,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 From a749edc89dd6f22e17c988014d28e85a05d57a2a Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 26 Mar 2022 11:57:53 +0100 Subject: [PATCH 2/2] Add test --- mkdocs/tests/config/config_options_tests.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mkdocs/tests/config/config_options_tests.py b/mkdocs/tests/config/config_options_tests.py index db01ba7869..e344aec307 100644 --- a/mkdocs/tests/config/config_options_tests.py +++ b/mkdocs/tests/config/config_options_tests.py @@ -323,6 +323,7 @@ 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): @@ -330,6 +331,7 @@ def test_edit_uri_bitbucket(self): 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): @@ -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):