Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,16 +1826,16 @@ def clean(self):
errors = []
null_char_list = ["0x00", "\x00"]
db_type = connection.vendor
if self.protocol or self.protocol == "":
if self.protocol is not None:
if not re.match(r"^[A-Za-z][A-Za-z0-9\.\-\+]+$", self.protocol): # https://tools.ietf.org/html/rfc3986#section-3.1
errors.append(ValidationError(f'Protocol "{self.protocol}" has invalid format'))
if self.protocol == "":
if not self.protocol:
self.protocol = None

if self.userinfo or self.userinfo == "":
if self.userinfo is not None:
if not re.match(r"^[A-Za-z0-9\.\-_~%\!\$&\'\(\)\*\+,;=:]+$", self.userinfo): # https://tools.ietf.org/html/rfc3986#section-3.2.1
errors.append(ValidationError(f'Userinfo "{self.userinfo}" has invalid format'))
if self.userinfo == "":
if not self.userinfo:
self.userinfo = None

if self.host:
Expand All @@ -1847,7 +1847,7 @@ def clean(self):
else:
errors.append(ValidationError("Host must not be empty"))

if self.port or self.port == 0:
if self.port is not None:
try:
int_port = int(self.port)
if not (0 <= int_port < 65536):
Expand All @@ -1856,7 +1856,7 @@ def clean(self):
except ValueError:
errors.append(ValidationError(f'Port "{self.port}" has invalid format - it is not a number'))

if self.path or self.path == "":
if self.path is not None:
while len(self.path) > 0 and self.path[0] == "/": # Endpoint store "root-less" path
self.path = self.path[1:]
if any(null_char in self.path for null_char in null_char_list):
Expand All @@ -1866,10 +1866,10 @@ def clean(self):
for remove_str in null_char_list:
self.path = self.path.replace(remove_str, "%00")
logger.error('Path "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
if self.path == "":
if not self.path:
self.path = None

if self.query or self.query == "":
if self.query is not None:
if len(self.query) > 0 and self.query[0] == "?":
self.query = self.query[1:]
if any(null_char in self.query for null_char in null_char_list):
Expand All @@ -1879,10 +1879,10 @@ def clean(self):
for remove_str in null_char_list:
self.query = self.query.replace(remove_str, "%00")
logger.error('Query "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
if self.query == "":
if not self.query:
self.query = None

if self.fragment or self.fragment == "":
if self.fragment is not None:
if len(self.fragment) > 0 and self.fragment[0] == "#":
self.fragment = self.fragment[1:]
if any(null_char in self.fragment for null_char in null_char_list):
Expand All @@ -1892,7 +1892,7 @@ def clean(self):
for remove_str in null_char_list:
self.fragment = self.fragment.replace(remove_str, "%00")
logger.error('Fragment "%s" has invalid format - It contains the NULL character. The following action was taken: %s', old_value, action_string)
if self.fragment == "":
if not self.fragment:
self.fragment = None

if errors:
Expand Down Expand Up @@ -2050,13 +2050,13 @@ def from_uri(uri):
query_parts.append(f"{k}={v}")
query_string = "&".join(query_parts)

protocol = url.scheme if url.scheme != "" else None
protocol = url.scheme or None
userinfo = ":".join(url.userinfo) if url.userinfo not in {(), ("",)} else None
host = url.host if url.host != "" else None
host = url.host or None
port = url.port
path = "/".join(url.path)[:500] if url.path not in {None, (), ("",)} else None
query = query_string[:1000] if query_string is not None and query_string != "" else None
fragment = url.fragment[:500] if url.fragment is not None and url.fragment != "" else None
query = query_string[:1000] if query_string is not None and query_string else None
fragment = url.fragment[:500] if url.fragment is not None and url.fragment else None

return Endpoint(
protocol=protocol,
Expand Down
4 changes: 0 additions & 4 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ preview = true
"S108", # tmp paths mentioned in tests are fine
]

"dojo/models.py" = [
"PLC1901", # fix later, causes some problems
]

[lint.flake8-boolean-trap]
extend-allowed-calls = ["dojo.utils.get_system_setting"]

Expand Down
Loading