Skip to content

Commit

Permalink
Escape double-backslashes in EdgeQL (#1019)
Browse files Browse the repository at this point in the history
These show up in regular expressions, so do a blanket find-and-replace
to a quadruple backslash.
  • Loading branch information
scotttrinh authored May 13, 2024
1 parent 8eac557 commit 2e247ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration-tests/lts/dbschema/queries/freeShape.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ select {
data := <str>$data,
required multi arg := {'asdf'},
enums := [Genre.Horror, Genre.Action],
regexp := re_match('\\s*(.*)?\\s+BEEP', " find me BEEP")[0]
};
15 changes: 15 additions & 0 deletions integration-tests/lts/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type GetMoviesStarringReturns,
deepArrayInput,
type DeepArrayInputArgs,
freeShape,
} from "./dbschema/queries";
import { type TestData, setupTests, teardownTests } from "./setupTeardown";

Expand Down Expand Up @@ -121,4 +122,18 @@ describe("queries", () => {

assert.equal(missing, null);
});

test("free shape", async () => {
const result = await freeShape(client, { data: "123" });

assert.ok(result);
assert.deepEqual(result, {
name: "arg",
points: 1234n,
data: "123",
arg: ["asdf"],
enums: ["Horror", "Action"],
regexp: "find me",
});
});
});
4 changes: 3 additions & 1 deletion packages/generate/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ ${hasArgs ? `export type ${argsInterfaceName} = ${params.types.args};\n` : ""}
export type ${returnsInterfaceName} = ${params.types.result};\
`;
const functionBody = `\
${params.types.query.trim().replace(/`/g, "\\`")}\`${hasArgs ? `, args` : ""});
${params.types.query.trim().replace(/\\/g, "\\\\").replace(/`/g, "\\`")}\`${
hasArgs ? `, args` : ""
});
`;

const tsImports =
Expand Down

0 comments on commit 2e247ad

Please sign in to comment.