mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 00:09:52 +00:00
fix: prevent SELECT with REPLACE/TRUNCATE functions from triggering danger warning
The DANGER_RE regex matched keywords anywhere in the SQL text, causing SELECT queries using REPLACE() or TRUNCATE() functions to incorrectly trigger the destructive-SQL warning dialog. Check only the first keyword of each semicolon-separated statement instead. Also fix dialog content overflow by adding min-w-0 to the <pre> element, and move macOS frameworks config from tauri.conf.json to CI-only TAURI_CONFIG so local `tauri dev` no longer requires libltdl/libodbc to be globally installed. Closes #135
This commit is contained in:
@@ -49,7 +49,7 @@ function onConfirm() {
|
||||
<p class="text-sm text-muted-foreground mb-3">{{ message || t("dangerDialog.message") }}</p>
|
||||
<pre
|
||||
v-if="details || sql"
|
||||
class="text-xs bg-muted p-3 rounded overflow-auto max-h-40 font-mono whitespace-pre-wrap"
|
||||
class="text-xs bg-muted p-3 rounded overflow-auto max-h-40 min-w-0 font-mono whitespace-pre-wrap"
|
||||
>{{ details || sql }}</pre
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
const DANGER_RE = /\b(DROP|DELETE|TRUNCATE|ALTER|UPDATE|MERGE|REPLACE)\b/i;
|
||||
const DANGER_RE = /^\s*(DROP|DELETE|TRUNCATE|ALTER|UPDATE|MERGE|REPLACE)\b/i;
|
||||
|
||||
export function stripSqlComments(sql: string): string {
|
||||
return sql
|
||||
@@ -16,7 +16,8 @@ export function stripSqlComments(sql: string): string {
|
||||
}
|
||||
|
||||
export function isDangerousSql(sql: string): boolean {
|
||||
return DANGER_RE.test(stripSqlComments(sql));
|
||||
const cleaned = stripSqlComments(sql);
|
||||
return cleaned.split(";").some((stmt) => DANGER_RE.test(stmt));
|
||||
}
|
||||
|
||||
export function useSqlExecution(deps: {
|
||||
|
||||
Reference in New Issue
Block a user