diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-03-27 18:06:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-27 18:06:22 +0300 |
commit | 746df6145239fd525056907deccb431f89bf8e41 (patch) | |
tree | 7fe5cdcfeea972d2880776b03ca6542d2a850345 | |
parent | 8a1830ca36ddea80f8bcbc20c1090280a0a5197a (diff) | |
parent | 81830cc77047ce39eab056a70b44a2d97848550c (diff) |
Merge pull request #10263 from nicoa/escape_base_uri_in_extlinks
escape base_uri in extlinks
-rw-r--r-- | sphinx/ext/extlinks.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py index b012c0f96..9b4e8cf47 100644 --- a/sphinx/ext/extlinks.py +++ b/sphinx/ext/extlinks.py @@ -18,6 +18,7 @@ Both, the url string and the caption string must escape ``%`` as ``%%``. """ import re +import sys import warnings from typing import Any, Dict, List, Tuple @@ -65,7 +66,13 @@ class ExternalLinksChecker(SphinxPostTransform): 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 |