Skip to content

refactor(postgresql): drop duplicate comment masking in the Table Browser SELECT gate (#1517) - #1605

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1517-postgres-split-statements
Oct 15, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1517-postgres-split-statements

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

isAllowedPostgresSelectQuery split the script with maskSqlLiteralsForLimitScan followed 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 uses codeUnitAt instead 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. SqlStatementSplitter follows MySQL-style lexing that PostgreSQL does not:

Input PostgreSQL SqlStatementSplitter
SELECT 'a\'; DELETE FROM t; --' literal 'a\' ends at the second quote, then DELETE runs \' is an escape: one SELECT statement, gate would allow the DELETE
SELECT 1 ` 2; DELETE FROM t; SELECT 1 ` 3 backtick is an operator character backtick quotes: one statement
SELECT 1 /* a /* b */ ; DELETE ...; */ nested comment, one SELECT comment ends at the first */: rejected

So 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.dart covering the three rows above plus semicolons in a quoted identifier and in a dollar quote.

Closes #1517

…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
@github-actions github-actions Bot added performance Theme parser epic label: performance core Core library logic and services backend Backend database driver execution and queries P3 Low priority / Polish & Enhancements labels Oct 15, 2026
@github-actions github-actions Bot added this to the 0.5.0 milestone Oct 15, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 8ad13b5 into dev Oct 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend database driver execution and queries core Core library logic and services P3 Low priority / Polish & Enhancements performance Theme parser epic label: performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant