1
0
mirror of https://github.com/django/django.git synced 2025-06-05 11:39:13 +00:00

Refs #30747 -- Removed django.utils.http.is_safe_url() per deprecation timeline.

This commit is contained in:
Mariusz Felisiak 2021-01-07 08:15:39 +01:00
parent 157ab32f34
commit 9e456f3166
3 changed files with 6 additions and 24 deletions

View File

@ -3,7 +3,6 @@ import calendar
import datetime import datetime
import re import re
import unicodedata import unicodedata
import warnings
from binascii import Error as BinasciiError from binascii import Error as BinasciiError
from email.utils import formatdate from email.utils import formatdate
from urllib.parse import ( from urllib.parse import (
@ -12,7 +11,6 @@ from urllib.parse import (
) )
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.regex_helper import _lazy_re_compile from django.utils.regex_helper import _lazy_re_compile
# based on RFC 7232, Appendix C # based on RFC 7232, Appendix C
@ -267,15 +265,6 @@ def url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):
) )
def is_safe_url(url, allowed_hosts, require_https=False):
warnings.warn(
'django.utils.http.is_safe_url() is deprecated in favor of '
'url_has_allowed_host_and_scheme().',
RemovedInDjango40Warning, stacklevel=2,
)
return url_has_allowed_host_and_scheme(url, allowed_hosts, require_https)
# Copied from urllib.parse.urlparse() but uses fixed urlsplit() function. # Copied from urllib.parse.urlparse() but uses fixed urlsplit() function.
def _urlparse(url, scheme='', allow_fragments=True): def _urlparse(url, scheme='', allow_fragments=True):
"""Parse a URL into 6 components: """Parse a URL into 6 components:

View File

@ -262,6 +262,8 @@ to remove usage of these features.
* ``django.utils.text.unescape_entities()`` is removed. * ``django.utils.text.unescape_entities()`` is removed.
* ``django.utils.http.is_safe_url()`` is removed.
See :ref:`deprecated-features-3.1` for details on these changes, including how See :ref:`deprecated-features-3.1` for details on these changes, including how
to remove usage of these features. to remove usage of these features.

View File

@ -5,12 +5,11 @@ from unittest import mock
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.http import ( from django.utils.http import (
base36_to_int, escape_leading_slashes, http_date, int_to_base36, base36_to_int, escape_leading_slashes, http_date, int_to_base36,
is_safe_url, is_same_domain, parse_etags, parse_http_date, parse_qsl, is_same_domain, parse_etags, parse_http_date, parse_qsl, quote_etag,
quote_etag, url_has_allowed_host_and_scheme, urlencode, url_has_allowed_host_and_scheme, urlencode, urlsafe_base64_decode,
urlsafe_base64_decode, urlsafe_base64_encode, urlsafe_base64_encode,
) )
@ -130,7 +129,7 @@ class Base36IntTests(SimpleTestCase):
self.assertEqual(base36_to_int(b36), n) self.assertEqual(base36_to_int(b36), n)
class IsSafeURLTests(SimpleTestCase): class URLHasAllowedHostAndSchemeTests(unittest.TestCase):
def test_bad_urls(self): def test_bad_urls(self):
bad_urls = ( bad_urls = (
'http://example.com', 'http://example.com',
@ -234,14 +233,6 @@ class IsSafeURLTests(SimpleTestCase):
False, False,
) )
def test_is_safe_url_deprecated(self):
msg = (
'django.utils.http.is_safe_url() is deprecated in favor of '
'url_has_allowed_host_and_scheme().'
)
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
is_safe_url('https://example.com', allowed_hosts={'example.com'})
class URLSafeBase64Tests(unittest.TestCase): class URLSafeBase64Tests(unittest.TestCase):
def test_roundtrip(self): def test_roundtrip(self):