1 Star 0 Fork 6

ZoeDong/python-django

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Fix-url-validator.patch 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
From: Pedro Schlickmann Mendes <windowsxpedro@gmail.com>
Date: Thu, 20 Jul 2023 12:59:59 +0100
Subject: Fixed URLValidator crash in some edge cases
Origin: upstream, https://github.com/django/django/commit/e8b4feddc34ffe5759ec21da8fa027e86e653f1c
Bug: https://code.djangoproject.com/ticket/33367
Last-Update: 2021-12-15
---
django/core/validators.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/django/core/validators.py b/django/core/validators.py
index 731ccf2d4690..6b28eef08dd2 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -110,15 +110,16 @@ class URLValidator(RegexValidator):
raise ValidationError(self.message, code=self.code, params={'value': value})
# Then check full URL
+ try:
+ splitted_url = urlsplit(value)
+ except ValueError:
+ raise ValidationError(self.message, code=self.code, params={'value': value})
try:
super().__call__(value)
except ValidationError as e:
# Trivial case failed. Try for possible IDN domain
if value:
- try:
- scheme, netloc, path, query, fragment = urlsplit(value)
- except ValueError: # for example, "Invalid IPv6 URL"
- raise ValidationError(self.message, code=self.code, params={'value': value})
+ scheme, netloc, path, query, fragment = splitted_url
try:
netloc = punycode(netloc) # IDN -> ACE
except UnicodeError: # invalid domain part
@@ -129,7 +130,7 @@ class URLValidator(RegexValidator):
raise
else:
# Now verify IPv6 in the netloc part
- host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
+ host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', splitted_url.netloc)
if host_match:
potential_ip = host_match[1]
try:
@@ -141,7 +142,7 @@ class URLValidator(RegexValidator):
# section 3.1. It's defined to be 255 bytes or less, but this includes
# one byte for the length of the name and one byte for the trailing dot
# that's used to indicate absolute names in DNS.
- if len(urlsplit(value).hostname) > 253:
+ if splitted_url.hostname is None or len(splitted_url.hostname) > 253:
raise ValidationError(self.message, code=self.code, params={'value': value})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ZoeDong/python-django.git
git@gitee.com:ZoeDong/python-django.git
ZoeDong
python-django
python-django
master

搜索帮助