Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ export interface ReconstructQueryOptions {
wrapLimitSubquery?: boolean;
}

/**
* Fold macOS "Smart Quotes" (curly ‘ ’ “ ”) back to straight ASCII quotes.
* SQL engines only accept straight ' as a string delimiter, so a filter typed
* as `status = 'x'` that the OS rewrote to `status = ‘x’` fails to parse
* ("unterminated quoted string").
*/
function normalizeSmartQuotes(s: string): string {
return s.replace(/[‘’‚‛]/g, "'").replace(/[“”„‟]/g, '"');
}

/**
* Reconstruct a SELECT query for a table tab with filters, sort, and limit.
* Optional overrides replace the tab's own clause values when provided.
Expand Down Expand Up @@ -345,8 +355,8 @@ export function reconstructTableQuery(
? options.limitOverride
: tab.limitClause;

const filter = filterClause ? `WHERE ${filterClause}` : "";
const sort = sortClause ? `ORDER BY ${sortClause}` : "";
const filter = filterClause ? `WHERE ${normalizeSmartQuotes(filterClause)}` : "";
const sort = sortClause ? `ORDER BY ${normalizeSmartQuotes(sortClause)}` : "";
const quotedTable = quoteTableRef(tab.activeTable, driver, tab.schema);

let baseQuery = `SELECT * FROM ${quotedTable} ${filter} ${sort}`.trim();
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ describe("editor", () => {
expect(result).toContain("ORDER BY");
expect(result).not.toMatch(/\s{2,}/);
});

it("should fold macOS smart quotes in the filter to straight ASCII", () => {
const tab = createMockTab({ filterClause: "status = ‘active’" });
const result = reconstructTableQuery(tab);
expect(result).toBe("SELECT * FROM \"users\" WHERE status = 'active'");
});
});

describe("formatExportFileName", () => {
Expand Down