Skip to content

Commit 6ed4bbb

Browse files
authored
Don't display 'replaceable hardcoded link' when link has a slash (#10137)
1 parent b1390c4 commit 6ed4bbb

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

sphinx/ext/extlinks.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def check_uri(self, refnode: nodes.reference) -> None:
7272
uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))
7373

7474
match = uri_pattern.match(uri)
75-
if match and match.groupdict().get('value'):
75+
if (
76+
match and
77+
match.groupdict().get('value') and
78+
'/' not in match.groupdict()['value']
79+
):
7680
# build a replacement suggestion
7781
msg = __('hardcoded link %r could be replaced by an extlink '
7882
'(try using %r instead)')

tests/roots/test-ext-extlinks-hardcoded-urls-multiple-replacements/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ https://github.com/octocat
1717

1818
`replaceable link`_
1919

20+
`non replaceable link <https://github.com/sphinx-doc/sphinx/pulls>`_
21+
2022
.. hyperlinks
2123
2224
.. _replaceable link: https://github.com/octocat

tests/test_ext_extlinks.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_all_replacements_suggested_if_multiple_replacements_possible(app, warni
2828
app.build()
2929
warning_output = warning.getvalue()
3030
# there should be six warnings for replaceable URLs, three pairs per link
31+
assert warning_output.count("WARNING: hardcoded link") == 6
3132
message = (
3233
"index.rst:%d: WARNING: hardcoded link 'https://github.com/octocat' "
3334
"could be replaced by an extlink (try using '%s' instead)"

0 commit comments

Comments
 (0)