Skip to content
Merged
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
2 changes: 1 addition & 1 deletion geonode/indexing/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def as_sql(self, compiler, connection, function=None, template=None):
sql, params = super().as_sql(compiler, connection, function, template)
value = params[1]
# sanitize search string
value = re.sub(r"[^0-9A-Za-z/_\.-]+", "", value)
value = re.sub(r"[^\w\s./\-]+", "", value, flags=re.UNICODE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

After sanitizing the search string, it's possible for it to contain only whitespace, or have leading/trailing whitespace. This could lead to queries like ' ':* which are valid but likely not what the user intends. It's good practice to strip() the value to handle these cases gracefully. An all-whitespace search would then correctly fall back to '*:*', which is consistent with an empty search. You can chain .strip() to the re.sub() call for a concise solution.

Suggested change
value = re.sub(r"[^\w\s./\-]+", "", value, flags=re.UNICODE)
value = re.sub(r"[^\w\s./\-]+", "", value, flags=re.UNICODE).strip()

value = f"{value or '*'}:*"
return sql, [params[0], value]

Expand Down
Loading