Repository navigation
refactor(postgresql): drop duplicate comment masking in the Table Browser SELECT gate (#1517) - #1605
Merged
Merged
Conversation
…T gate _splitPostgresStatements masked literals and comments with maskSqlLiteralsForLimitScan and then ran a second, hand-written comment masker over the result. The first pass already blanks comments, strings, quoted identifiers and dollar quotes, so the second one never changed anything. It is removed and the split reads code units. SqlStatementSplitter is not used here on purpose: it treats a backslash as a quote escape and a backtick as a quote (MySQL rules), so "SELECT 'a\\'; DELETE FROM t; --'" would be one statement for the gate while PostgreSQL runs the DELETE. Tests pin that and the nested block comments. Closes #1517
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.
Summary
isAllowedPostgresSelectQuerysplit the script withmaskSqlLiteralsForLimitScanfollowed by a hand-written_maskPostgresComments. The first pass already blanks comments, strings, quoted identifiers and dollar quotes, so the second pass produced a third copy of the text and never changed it. It is deleted (~35 lines), and the semicolon scan usescodeUnitAtinstead of one-character strings.Why not
SqlStatementSplitter.spans(the issue's proposal)This function is the gate that keeps writes out of the Table Browser, so it has to split where PostgreSQL splits.
SqlStatementSplitterfollows MySQL-style lexing that PostgreSQL does not:SqlStatementSplitterSELECT 'a\'; DELETE FROM t; --''a\'ends at the second quote, thenDELETEruns\'is an escape: one SELECT statement, gate would allow the DELETESELECT 1 ` 2; DELETE FROM t; SELECT 1 ` 3SELECT 1 /* a /* b */ ; DELETE ...; */*/: rejectedSo the existing masking is kept (it already follows PostgreSQL), and tests pin these cases.
Tests (not run locally; CI will)
New test in
postgres_table_utils_test.dartcovering the three rows above plus semicolons in a quoted identifier and in a dollar quote.Closes #1517