⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(comments): address follow-up review feedback
Tin44df12bfe93e
diff --git a/apps/api/src/activity/index.ts b/apps/api/src/activity/index.tsindex 73cc55a32..4e87d54d8 100644--- a/apps/api/src/activity/index.ts+++ b/apps/api/src/activity/index.ts@@ -1,4 +1,5 @@import { Hono } from "hono";+import { HTTPException } from "hono/http-exception";import { describeRoute, resolver, validator } from "hono-openapi";import * as v from "valibot";import { subscribeToEvent } from "../events";@@ -70,6 +71,11 @@ const activity = new Hono<{requireWorkspacePermission({ task: ["update"] }),async (c) => {const { taskId, userId, message, type, eventData } = c.req.valid("json");+ if (type === "comment") {+ throw new HTTPException(400, {+ message: "Use the comment endpoint to create comments",+ });+ }const activity = await createActivity(taskId,type,diff --git a/apps/web/src/lib/normalize-comment-markdown.test.ts b/apps/web/src/lib/normalize-comment-markdown.test.tsindex 4f1845156..071a65d7d 100644--- a/apps/web/src/lib/normalize-comment-markdown.test.ts+++ b/apps/web/src/lib/normalize-comment-markdown.test.ts@@ -34,6 +34,14 @@ describe("normalizeCommentMarkdown", () => {expect(result).toBe("Text `code \u00A0value` more text");});+ it("preserves non-breaking spaces inside multiline inline code", () => {+ const markdown = "Text `code\n \u00A0value` more\u00A0text";++ const result = normalizeCommentMarkdown(markdown);++ expect(result).toBe("Text `code\n \u00A0value` more text");+ });+it("preserves non-breaking spaces inside fenced code blocks", () => {const markdown ="Before \n```html\n<div> \u00A0</div>\n```\nAfter\u00A0";diff --git a/apps/web/src/lib/normalize-comment-markdown.ts b/apps/web/src/lib/normalize-comment-markdown.tsindex baf29c456..9d74b12bf 100644--- a/apps/web/src/lib/normalize-comment-markdown.ts+++ b/apps/web/src/lib/normalize-comment-markdown.ts@@ -66,38 +66,44 @@ export function normalizeCommentMarkdown(markdown: string) {const normalizedNewlines = markdown.replace(/\r\n/g, "\n");const lines = normalizedNewlines.match(/[^\n]*(?:\n|$)/g) ?? [];let fence: { marker: string; length: number } | null = null;+ let textSegment = "";+ let output = "";- return lines- .map((lineWithEnding) => {- const line = lineWithEnding.endsWith("\n")- ? lineWithEnding.slice(0, -1)- : lineWithEnding;-- if (fence) {- const closingFence = /^ {0,3}(`{3,}|~{3,})[\t ]*$/.exec(line);- if (- closingFence &&- closingFence[1][0] === fence.marker &&- closingFence[1].length >= fence.length- ) {- fence = null;- }- return lineWithEnding;- }+ for (const lineWithEnding of lines) {+ const line = lineWithEnding.endsWith("\n")+ ? lineWithEnding.slice(0, -1)+ : lineWithEnding;- const openingFence = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);+ if (fence) {+ output += lineWithEnding;+ const closingFence = /^ {0,3}(`{3,}|~{3,})[\t ]*$/.exec(line);if (- openingFence &&- (openingFence[1][0] === "~" || !openingFence[2].includes("`"))+ closingFence &&+ closingFence[1][0] === fence.marker &&+ closingFence[1].length >= fence.length) {- fence = {- marker: openingFence[1][0],- length: openingFence[1].length,- };- return lineWithEnding;+ fence = null;}+ continue;+ }++ const openingFence = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);+ if (+ openingFence &&+ (openingFence[1][0] === "~" || !openingFence[2].includes("`"))+ ) {+ output += normalizeInlineMarkdown(textSegment);+ textSegment = "";+ fence = {+ marker: openingFence[1][0],+ length: openingFence[1].length,+ };+ output += lineWithEnding;+ continue;+ }++ textSegment += lineWithEnding;+ }- return normalizeInlineMarkdown(lineWithEnding);- })- .join("");+ return output + normalizeInlineMarkdown(textSegment);}diff --git a/tests/api-integration/comment.test.ts b/tests/api-integration/comment.test.tsindex 93f2d235f..b2c0e9d02 100644--- a/tests/api-integration/comment.test.ts+++ b/tests/api-integration/comment.test.ts@@ -97,7 +97,7 @@ describe("API integration: task comments", () => {expect(legacyComments).toHaveLength(0);});- it("rejects comments over the activity API length limit", async () => {+ it("rejects creating comments over the activity API length limit", async () => {const member = await createWorkspaceMember();const { project, columns } = await createProjectFixture({workspaceId: member.workspace.id,@@ -118,6 +118,35 @@ describe("API integration: task comments", () => {mockAuthenticatedSession(member.user);const { app } = createApp();+ const overlongComment = "x".repeat(10_001);+ const response = await app.request("/api/activity/comment", {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ taskId: task.id, comment: overlongComment }),+ });++ expect(response.status).toBe(400);+ });++ it("rejects updating comments over the activity API length limit", async () => {+ const member = await createWorkspaceMember();+ const { project, columns } = await createProjectFixture({+ workspaceId: member.workspace.id,+ });+ const [task] = await db+ .insert(schema.taskTable)+ .values({+ projectId: project.id,+ title: "Comment length limit",+ status: "to-do",+ columnId: columns.todo.id,+ priority: "medium",+ number: 1,+ position: 1,+ })+ .returning();+ mockAuthenticatedSession(member.user);+ const { app } = createApp();const createResponse = await app.request("/api/activity/comment", {method: "POST",headers: { "content-type": "application/json" },@@ -125,16 +154,9 @@ describe("API integration: task comments", () => {});expect(createResponse.status).toBe(200);const createdComment = (await createResponse.json()) as { id: string };-const overlongComment = "x".repeat(10_001);- const createOverLimitResponse = await app.request("/api/activity/comment", {- method: "POST",- headers: { "content-type": "application/json" },- body: JSON.stringify({ taskId: task.id, comment: overlongComment }),- });- expect(createOverLimitResponse.status).toBe(400);- const updateOverLimitResponse = await app.request("/api/activity/comment", {+ const response = await app.request("/api/activity/comment", {method: "PUT",headers: { "content-type": "application/json" },body: JSON.stringify({@@ -142,6 +164,41 @@ describe("API integration: task comments", () => {comment: overlongComment,}),});- expect(updateOverLimitResponse.status).toBe(400);++ expect(response.status).toBe(400);+ });++ it("rejects comments through the generic activity endpoint", async () => {+ const member = await createWorkspaceMember();+ const { project, columns } = await createProjectFixture({+ workspaceId: member.workspace.id,+ });+ const [task] = await db+ .insert(schema.taskTable)+ .values({+ projectId: project.id,+ title: "Generic comment activity",+ status: "to-do",+ columnId: columns.todo.id,+ priority: "medium",+ number: 1,+ position: 1,+ })+ .returning();+ mockAuthenticatedSession(member.user);+ const { app } = createApp();++ const response = await app.request("/api/activity/create", {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ taskId: task.id,+ userId: member.user.id,+ message: "Comment through generic endpoint",+ type: "comment",+ }),+ });++ expect(response.status).toBe(400);});});