mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #10263 from nicoa/escape_base_uri_in_extlinks
escape base_uri in extlinks
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user