Skip to content

Commit c3002ff

Browse files
committed
v2.24.3: Add --skip-config to rebalance to not reload the config since it's been loaded by the tmux caller already; improve shellQuote() cosmetics
1 parent 5ab646e commit c3002ff

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@clickup/pg-microsharding",
33
"description": "Microshards support for PostgreSQL",
4-
"version": "2.24.2",
4+
"version": "2.24.3",
55
"license": "MIT",
66
"keywords": [
77
"postgresql",

src/actions/actionRebalance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export async function actionRebalance(args: Args): Promise<boolean> {
4747
const parallelism = Number(args["parallelism"] ?? "") || 3;
4848
const deactivateSQL = String(args["deactivate-sql"] || "") || undefined;
4949
const wait = args["wait"];
50-
const skipConfig = args["skip-config"];
5150

5251
const { islandNosToDsn, islands } = await calcIslandWeights({
5352
dsns,
@@ -159,7 +158,7 @@ export async function actionRebalance(args: Args): Promise<boolean> {
159158
: []),
160159
...(deactivateSQL ? ["--deactivate-sql", deactivateSQL] : []),
161160
...(wait ? ["--wait"] : []),
162-
...(skipConfig ? ["--skip-config"] : []),
161+
"--skip-config",
163162
],
164163
})),
165164
);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { shellQuote } from "../quote";
2+
3+
test("shellQuote should escape semicolon", () => {
4+
expect(shellQuote(";")).toBe("\\;");
5+
});
6+
7+
test("shellQuote should return safe strings unchanged", () => {
8+
expect(shellQuote("hello")).toBe("hello");
9+
expect(shellQuote("test_123")).toBe("test_123");
10+
expect(shellQuote("path/to/file.txt")).toBe("path/to/file.txt");
11+
expect(shellQuote("[email protected]")).toBe("[email protected]");
12+
expect(shellQuote("key1=value1,key2=value2")).toBe("key1=value1,key2=value2");
13+
});
14+
15+
test("shellQuote should handle key=value pattern", () => {
16+
expect(shellQuote("key=value with spaces")).toBe("key='value with spaces'");
17+
expect(shellQuote("database=my database")).toBe("database='my database'");
18+
});
19+
20+
test("shellQuote should handle --key=value pattern", () => {
21+
expect(shellQuote("--verbose=true")).toBe("--verbose=true");
22+
expect(shellQuote("--database=my database")).toBe("--database='my database'");
23+
});
24+
25+
test("shellQuote should quote strings with special characters", () => {
26+
expect(shellQuote("hello world")).toBe("'hello world'");
27+
expect(shellQuote("path with spaces")).toBe("'path with spaces'");
28+
expect(shellQuote("special!@#$%")).toBe("'special!@#$%'");
29+
});
30+
31+
test("shellQuote should escape single quotes in quoted strings", () => {
32+
expect(shellQuote("don't")).toBe("'don'\\''t'");
33+
expect(shellQuote("it's a test")).toBe("'it'\\''s a test'");
34+
expect(shellQuote("'quoted'")).toBe("''\\''quoted'\\'''");
35+
});
36+
37+
test("shellQuote should handle key=value with single quotes in value", () => {
38+
expect(shellQuote("name=John's file")).toBe("name='John'\\''s file'");
39+
expect(shellQuote("--title=Bob's Project")).toBe(
40+
"--title='Bob'\\''s Project'",
41+
);
42+
});
43+
44+
test("shellQuote should handle empty string", () => {
45+
expect(shellQuote("")).toBe("''");
46+
});

src/internal/quote.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ export type Value = string | number | null | Sql | Ident;
44
* Quotes the value to be used as a shell argument.
55
*/
66
export function shellQuote(s: string): string {
7-
return s.match(/^[-=a-zA-Z_0-9:/@.]+$/)
8-
? s
9-
: "'" + s.replace(/'/g, "'\\''") + "'";
7+
function quote(s: string): string {
8+
return "'" + s.replace(/'/g, "'\\''") + "'";
9+
}
10+
11+
return s === ";"
12+
? "\\;"
13+
: s.match(/^[-a-z_0-9:/@.=,]+$/is)
14+
? s
15+
: s.match(/^((?:--)?[-a-z_0-9]+=)(.*)$/is)
16+
? RegExp.$1 + quote(RegExp.$2)
17+
: quote(s);
1018
}
1119

1220
/**

0 commit comments

Comments
 (0)