From 2190e892603d238e1a1fc40477bf30d131c22acc Mon Sep 17 00:00:00 2001 From: dirkf Date: Mon, 7 Apr 2025 16:00:11 +0100 Subject: [PATCH] [utils] Support optional `safe` argument for `escape_rfc3986()` --- youtube_dl/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index ac1e78002..c4262936e 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -4204,12 +4204,16 @@ def lowercase_escape(s): s) -def escape_rfc3986(s): +def escape_rfc3986(s, safe=None): """Escape non-ASCII characters as suggested by RFC 3986""" if sys.version_info < (3, 0): s = _encode_compat_str(s, 'utf-8') + if safe is not None: + safe = _encode_compat_str(safe, 'utf-8') + if safe is None: + safe = b"%/;:@&=+$,!~*'()?#[]" # ensure unicode: after quoting, it can always be converted - return compat_str(compat_urllib_parse.quote(s, b"%/;:@&=+$,!~*'()?#[]")) + return compat_str(compat_urllib_parse.quote(s, safe)) def escape_url(url):