Skip to content

Commit

Permalink
Don't display 'replaceable hardcoded link' when link has a slash (sph…
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Oct 5, 2022
1 parent b1390c4 commit 6ed4bbb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sphinx/ext/extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def check_uri(self, refnode: nodes.reference) -> None:
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)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test_ext_extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 6ed4bbb

Please sign in to comment.