fix: sanitize SQL queries by removing trailing semicolons

This commit is contained in:
Christopher Gondek 2025-11-05 11:23:54 +01:00
parent dde61f447d
commit 3fbb41b980

View file

@ -86,6 +86,9 @@ class DataQueryService:
""" """
max_limit = settings.SQL_ROW_LIMIT max_limit = settings.SQL_ROW_LIMIT
# Strip trailing semicolons and whitespace to prevent multi-statement errors
query = query.rstrip("; \t\n\r")
# Remove comments and normalize whitespace for parsing # Remove comments and normalize whitespace for parsing
cleaned_query = re.sub(r"--.*$", "", query, flags=re.MULTILINE) cleaned_query = re.sub(r"--.*$", "", query, flags=re.MULTILINE)
cleaned_query = re.sub(r"/\*.*?\*/", "", cleaned_query, flags=re.DOTALL) cleaned_query = re.sub(r"/\*.*?\*/", "", cleaned_query, flags=re.DOTALL)