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:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-03-27 17:55:10 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2022-03-27 17:55:10 +0300
commitaee4e42b81d56c57e1311176ce175ba3374baa0a (patch)
tree9311cafcb7ce2b758d0af35eb036abe86eb136c3
parent554f589fde62473552a16194b4f77f74c3decf11 (diff)
extlink: Strip a leading backslash on compiling pattern
-rw-r--r--sphinx/ext/extlinks.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py
index 6601f0677..a574d665a 100644
--- a/sphinx/ext/extlinks.py
+++ b/sphinx/ext/extlinks.py
@@ -26,6 +26,7 @@
"""
import re
+import sys
import warnings
from typing import Any, Dict, List, Tuple
@@ -70,7 +71,12 @@ class ExternalLinksChecker(SphinxPostTransform):
title = refnode.astext()
for alias, (base_uri, _caption) in self.app.config.extlinks.items():
- uri_pattern = re.compile(re.escape(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