Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2022-10-05 16:47:16 +0300
committerGitHub <noreply@github.com>2022-10-05 16:47:16 +0300
commit6ed4bbba396eb410c4d00e5f9881aa621cec749a (patch)
treef00caa07b2cd88ae13a18beb27db7ee75419f5ad
parentb1390c4191319e75d14ce3e6e73ef43c31d981b4 (diff)
Don't display 'replaceable hardcoded link' when link has a slash (#10137)
-rw-r--r--sphinx/ext/extlinks.py6
-rw-r--r--tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst2
-rw-r--r--tests/test_ext_extlinks.py1
3 files changed, 8 insertions, 1 deletions
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py
index c03cb78ba..3ee0735d4 100644
--- a/sphinx/ext/extlinks.py
+++ b/sphinx/ext/extlinks.py
@@ -72,7 +72,11 @@ class ExternalLinksChecker(SphinxPostTransform):
uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))
match = uri_pattern.match(uri)
- if match and match.groupdict().get('value'):
+ if (
+ match and
+ match.groupdict().get('value') and
+ '/' not in match.groupdict()['value']
+ ):
# build a replacement suggestion
msg = __('hardcoded link %r could be replaced by an extlink '
'(try using %r instead)')
diff --git a/tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst b/tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst
index c8b008ea2..162b3611a 100644
--- a/tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst
+++ b/tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst
@@ -17,6 +17,8 @@ https://github.com/octocat
`replaceable link`_
+`non replaceable link <https://github.com/sphinx-doc/sphinx/pulls>`_
+
.. hyperlinks
.. _replaceable link: https://github.com/octocat
diff --git a/tests/test_ext_extlinks.py b/tests/test_ext_extlinks.py
index 0e257364e..7634db688 100644
--- a/tests/test_ext_extlinks.py
+++ b/tests/test_ext_extlinks.py
@@ -28,6 +28,7 @@ def test_all_replacements_suggested_if_multiple_replacements_possible(app, warni
app.build()
warning_output = warning.getvalue()
# there should be six warnings for replaceable URLs, three pairs per link
+ assert warning_output.count("WARNING: hardcoded link") == 6
message = (
"index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' "
"could be replaced by an extlink (try using '%s' instead)"