Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(cli): sanitize jq string output and size attachment comments

Andrej67603f02f0f8
diff --git a/packages/cli/src/commands/task/attach.ts b/packages/cli/src/commands/task/attach.ts
index f6f8d8600..6af76112b 100644
--- a/packages/cli/src/commands/task/attach.ts
+++ b/packages/cli/src/commands/task/attach.ts
@@ -31,6 +31,7 @@ import { Output } from "../../output/output.js";
import { withSpinner } from "../../output/spinner.js";
import { promptTheme } from "../../prompts/prompt-theme.js";
import { fetchTask, resolveTask } from "../../tasks/resolve-task.js";
+import { Session } from "../../services/session.js";
import { ApiLayer } from "../api-layer.js";
const FILES_HINT = "For example: kaneo task attach KAN-12 screenshot.png";
@@ -113,8 +114,6 @@ const previewLines = Effect.fnUntraced(function* (
return lines;
});
-const PLACEHOLDER_ASSET_URL = `https://${"x".repeat(64)}/api/asset/${"x".repeat(64)}`;
-
export const runTaskAttach = Effect.fn("command.task.attach")(
function* (options: {
readonly task: string;
@@ -123,6 +122,7 @@ export const runTaskAttach = Effect.fn("command.task.attach")(
readonly message: Option.Option<string>;
readonly messageFile: Option.Option<string>;
}) {
+ const session = yield* Session;
const message = yield* readTextInput({
value: options.message,
file: options.messageFile,
@@ -150,7 +150,7 @@ export const runTaskAttach = Effect.fn("command.task.attach")(
text,
files.map((file) => ({
name: file.name,
- url: PLACEHOLDER_ASSET_URL,
+ url: `${session.apiUrl}/api/asset/${"x".repeat(32)}`,
contentType: file.contentType,
size: file.bytes.byteLength,
kind: isInlineImageType(file.contentType) ? "image" : "attachment",
diff --git a/packages/cli/src/jq/format-jq-output.test.ts b/packages/cli/src/jq/format-jq-output.test.ts
index c1d59b1a2..477d2ca9b 100644
--- a/packages/cli/src/jq/format-jq-output.test.ts
+++ b/packages/cli/src/jq/format-jq-output.test.ts
@@ -15,4 +15,10 @@ describe("formatJqResults", () => {
it("prints nothing when the expression yields no results", () => {
expect(formatJqResults([])).toBe("");
});
+
+ it("strips terminal control characters from string results", () => {
+ expect(formatJqResults(["title\u001b]0;pwned\u0007"])).toBe(
+ "title]0;pwned\n",
+ );
+ });
});
diff --git a/packages/cli/src/jq/format-jq-output.ts b/packages/cli/src/jq/format-jq-output.ts
index fc5f5808f..8262d94fb 100644
--- a/packages/cli/src/jq/format-jq-output.ts
+++ b/packages/cli/src/jq/format-jq-output.ts
@@ -1,8 +1,10 @@
+import { sanitizeText } from "../render/sanitize.js";
+
export function formatJqResults(results: ReadonlyArray<unknown>): string {
return results
.map(
(value) =>
- `${typeof value === "string" ? value : (JSON.stringify(value) ?? "null")}\n`,
+ `${typeof value === "string" ? sanitizeText(value) : (JSON.stringify(value) ?? "null")}\n`,
)
.join("");
}