Repository navigation
fix(grid): make Copy as INSERT name the table the rows came from - #539
Merged
Merged
Conversation
Closes #409. The statement was built with a literal placeholder: INSERT INTO your_table (`id`, `name`) VALUES (1, 'Alice'); Pasting it fails with "Table 'db.your_table' doesn't exist", which is the harmless outcome. On a schema where that name happens to be real, it succeeds and writes the row somewhere the user never chose — which is why this was filed as security rather than papercut. The table now comes from resolveEditTarget, the same resolver Save uses, against the active editor tab's SQL. Reusing it is deliberate: a join or a CTE selects columns belonging to more than one table, so there is no single table an INSERT of that row could target, and it already refuses exactly those shapes. Where it refuses, the menu item is disabled and its hover text gives the reason rather than leaving a dead entry with no explanation. The click handler re-checks, since disabled is a UI convention and not a lock. Identifiers now go through quoteIdentifier instead of bare backticks, so a table or column name containing a backtick cannot terminate the quoting early. MenuItem gains an optional `title`. Nothing else used it; a disabled item with no way to say why is the reason it exists. Three tests in the browser suite. All three fail against the previous implementation — verified by stashing the two source files and re-running. Also dropped `extractTableName` from that file's sql-generator mock. It was removed from the module in #529, so the mock was describing an export that no longer exists. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Closes #409.
The bug
The statement was built with a literal placeholder:
Pasting that fails with
Table 'db.your_table' doesn't exist— the harmless outcome. On a schema where that name happens to be real, it succeeds, and writes the row somewhere the user never chose. That is why this was filed as security rather than papercut.The fix
The table now comes from
resolveEditTarget— the same resolver Save uses — against the active editor tab's SQL.Reusing it is deliberate, not convenience. A join or a CTE selects columns belonging to more than one table, so there is no single table an INSERT of that row could target, and
resolveEditTargetalready refuses exactly those shapes. Where it refuses, the menu item is disabled and its hover text carries the reason, rather than leaving a dead entry with no explanation. The click handler re-checks anyway, sincedisabledis a UI convention and not a lock.Identifiers go through
quoteIdentifierinstead of bare backticks, so a table or column name containing a backtick can't terminate the quoting early.MenuItemgains an optionaltitle. Nothing else used one; a disabled item with no way to say why is the reason it now exists.Tests
Three in the browser suite — the table is named, a name needing quoting survives, and a join disables the item with a reason. All three fail against the previous implementation, verified by stashing
ResultsGrid.tsxandContextMenu.tsxand re-running.Also
Dropped
extractTableNamefrom that file'ssql-generatormock. #529 removed it from the module, so the mock was describing an export that no longer exists.Local: 1693 unit + 295 browser tests green, tsc/dprint/eslint clean.
🤖 Generated with Claude Code