Skip to content

Commit

Permalink
feat: add unescape []
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Mar 4, 2024
1 parent 8baf646 commit e48157b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib/sql-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("Escape SQL", () => {
it("unescape identity", () => {
expect(unescapeIdentity(`"users"`)).toBe("users");
expect(unescapeIdentity(`"us""ers"`)).toBe(`us"ers`);
expect(unescapeIdentity(`[users]`)).toBe(`users`);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/sql-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function escapeIdentity(str: string) {
}

export function unescapeIdentity(str: string) {
let r = str.replace(/^["`]/g, "");
r = r.replace(/["`]$/g, "");
let r = str.replace(/^["`[]/g, "");
r = r.replace(/["`\]]$/g, "");
r = r.replace(/""/g, `"`);
return r;
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export function validateConnectionEndpoint(
try {
const url = new URL(endpoint);

if (url.protocol !== "wss:" && url.protocol !== "libsql:") {
if (
url.protocol !== "wss:" &&
url.protocol !== "libsql:" &&
url.protocol !== "ws:"
) {
return [false, "We only support wss:// or libsql:// at the moment."];
}

Expand Down

0 comments on commit e48157b

Please sign in to comment.