Merge pull request #10 from valueonag/chore/limit-row-count

fix: sanitize SQL queries by removing trailing semicolons
This commit is contained in:
Christopher Gondek 2025-11-05 11:24:39 +01:00 committed by GitHub
commit 5b8daa4e49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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)