diff --git a/dojo/models.py b/dojo/models.py index 02dcc0f468c..1adb0dfd797 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -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: @@ -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): @@ -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): @@ -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): @@ -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): @@ -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: @@ -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, diff --git a/ruff.toml b/ruff.toml index f6a0acd8196..4653259741d 100644 --- a/ruff.toml +++ b/ruff.toml @@ -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"]