Skip to content

Commit

Permalink
Merge pull request #10263 from nicoa/escape_base_uri_in_extlinks
Browse files Browse the repository at this point in the history
escape base_uri in extlinks
  • Loading branch information
tk0miya committed Mar 27, 2022
2 parents 8a1830c + 81830cc commit 746df61
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sphinx/ext/extlinks.py
Expand Up @@ -18,6 +18,7 @@
"""

import re
import sys
import warnings
from typing import Any, Dict, List, Tuple

Expand Down Expand Up @@ -65,7 +66,13 @@ def check_uri(self, refnode: nodes.reference) -> None:
title = refnode.astext()

for alias, (base_uri, _caption) in self.app.config.extlinks.items():
uri_pattern = re.compile(base_uri.replace('%s', '(?P<value>.+)'))
if sys.version_info < (3, 7):
# Replace a leading backslash because re.escape() inserts a backslash before %
# on python 3.6
uri_pattern = re.compile(re.escape(base_uri).replace('\\%s', '(?P<value>.+)'))
else:
uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))

match = uri_pattern.match(uri)
if match and match.groupdict().get('value'):
# build a replacement suggestion
Expand Down

0 comments on commit 746df61

Please sign in to comment.