Skip to content

Commit

Permalink
extlink: Strip a leading backslash on compiling pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Mar 27, 2022
1 parent 554f589 commit aee4e42
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sphinx/ext/extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""

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

Expand Down Expand Up @@ -70,7 +71,12 @@ 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(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
Expand Down

0 comments on commit aee4e42

Please sign in to comment.