fix: trim leading whitespace before stripping EXPLAIN/PROFILE prefix to avoid crash#4181
Open
imilinovic wants to merge 1 commit into
Open
fix: trim leading whitespace before stripping EXPLAIN/PROFILE prefix to avoid crash#4181imilinovic wants to merge 1 commit into
imilinovic wants to merge 1 commit into
Conversation
Contributor
Author
TrackingStandard development
CI Testing Labels
Documentation checklist
|
31d2640 to
fc0a56b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a parsing/preprocessing edge case where leading whitespace before EXPLAIN/PROFILE caused incorrect prefix stripping (via substr(...)), leading to assertion failures or Cypher parse errors. It does so by trimming leading whitespace at the ParseQuery entry point, ensuring downstream logic can safely assume the query starts with the first significant token.
Changes:
- Trim leading whitespace in
ParseQuerybefore query stripping/caching and downstream processing. - Add Gherkin scenarios to ensure
EXPLAINandPROFILEwork even when the query begins with whitespace/newlines.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/query/cypher_query_interpreter.cpp |
Trims leading whitespace once at parse entry to prevent bad EXPLAIN/PROFILE prefix slicing. |
tests/gql_behave/tests/memgraph_V1/features/memgraph.feature |
Adds regression scenarios for leading-whitespace EXPLAIN and PROFILE. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
DavIvek
approved these changes
May 26, 2026
fc0a56b to
d27778e
Compare
…4137) PrepareExplainQuery and PrepareProfileQuery stripped the keyword via query_string.substr(8) on the raw query. When the query had leading whitespace before EXPLAIN/PROFILE, this sliced into the inner query instead of removing the keyword — either failing the MG_ASSERT that expects a CypherQuery, or producing a Cypher parse error. LTrim the raw query before the substr so the prefix is removed correctly regardless of leading whitespace.
d27778e to
786fb74
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



PrepareExplainQuery and PrepareProfileQuery stripped the keyword via query_string.substr(8) on the raw query. When the query had leading whitespace before EXPLAIN/PROFILE, this sliced into the inner query instead of removing the keyword — either failing the MG_ASSERT that expects a CypherQuery, or producing a Cypher parse error.
LTrim the raw query before the substr so the prefix is removed correctly regardless of leading whitespace.