8000 extlink: Strip a leading backslash on compiling pattern · sphinx-doc/sphinx@aee4e42 · GitHub
[go: up one dir, main page]

Skip to content

Commit aee4e42

Browse files
committed
extlink: Strip a leading backslash on compiling pattern
1 parent 554f589 commit aee4e42

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sphinx/ext/extlinks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"""
2727

2828
import re
29+
import sys
2930
import warnings
3031
from typing import Any, Dict, List, Tuple
3132

@@ -70,7 +71,12 @@ def check_uri(self, refnode: nodes.reference) -> None:
7071
title = refnode.astext()
7172

7273
for alias, (base_uri, _caption) in self.app.config.extlinks.items():
73-
uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))
74+
if sys.version_info < (3, 7):
75+
# Replace a leading backslash because re.escape() inserts a backslash before % on python 3.6
76+
uri_pattern = re.compile(re.escape(base_uri).replace('\\%s', '(?P<value>.+)'))
77+
else:
78+
uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))
79+
7480
match = uri_pattern.match(uri)
7581
if match and match.groupdict().get('value'):
7682
# build a replacement suggestion

0 commit comments

Comments
 (0)
0