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:
-rw-r--r--sphinx/ext/extlinks.py9
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