Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explain query plan select is too strict about whitespace #1588

Closed
simonw opened this issue Jan 9, 2022 · 3 comments
Closed

explain query plan select is too strict about whitespace #1588

simonw opened this issue Jan 9, 2022 · 3 comments
Labels
bug minor Minor bugs (not high priority)

Comments

@simonw
Copy link
Owner

simonw commented Jan 9, 2022

explain query plan select * from facetable is allowed: https://latest.datasette.io/fixtures?sql=explain+query+plan+select+*+from+facetable

But... explain query plan select * from facetable (with two spaces before the select) returns a "Statement must be a SELECT" error: https://latest.datasette.io/fixtures?sql=explain+query+plan++select+*+from+facetable

@simonw simonw transferred this issue from simonw/sqlite-utils Jan 9, 2022
@simonw simonw added bug minor Minor bugs (not high priority) labels Jan 9, 2022
@simonw
Copy link
Owner Author

simonw commented Jan 9, 2022

Relevant code:

allowed_sql_res = [
re.compile(r"^select\b"),
re.compile(r"^explain select\b"),
re.compile(r"^explain query plan select\b"),
re.compile(r"^with\b"),
re.compile(r"^explain with\b"),
re.compile(r"^explain query plan with\b"),
]

def validate_sql_select(sql):
sql = "\n".join(
line for line in sql.split("\n") if not line.strip().startswith("--")
)
sql = sql.strip().lower()
if not any(r.match(sql) for r in allowed_sql_res):
raise InvalidSql("Statement must be a SELECT")
for r, msg in disallawed_sql_res:
if r.search(sql):
raise InvalidSql(msg)

@simonw
Copy link
Owner Author

simonw commented Jan 9, 2022

I think this is the fix:

re.compile(r"^explain\s+query\s+plan\s+select\b"),

@simonw simonw closed this as completed in 63537dd Jan 13, 2022
@simonw
Copy link
Owner Author

simonw commented Jan 13, 2022

@simonw simonw added this to the Datasette 0.60 milestone Jan 13, 2022
simonw added a commit that referenced this issue Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug minor Minor bugs (not high priority)
Projects
None yet
Development

No branches or pull requests

1 participant