Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions FIX_PROPOSAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
To fix the issue, we need to modify the `formatPath()` function in `WelcomeRecentFiles.tsx` to apply max-length truncation even when the path has two or fewer segments. Here's the exact code fix:

```typescript
function formatPath(path: string, maxLength: number = 60): string {
const normalized = path.replace(/\\/g, '/'); // Normalize slashes
if (normalized.length <= maxLength) {
return normalized;
}

const parts = normalized.split('/');
if (parts.length <= 2) {
// Apply max-length truncation
if (normalized.length > maxLength) {
const excess = normalized.length - maxLength;
const middleIndex = Math.floor(normalized.length / 2);
const left = normalized.substring(0, middleIndex - excess / 2);
const right = normalized.substring(middleIndex + excess / 2);
return `${left}...${right}`;
}
Comment on lines +14 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Middle-truncation math can still exceed maxLength

At Line 14–Line 19, excess is computed as len - maxLength, but the returned value adds ... afterward. That means final length can become maxLength + 3. Reserve space for the ellipsis before splitting.

Suggested fix
-      const excess = normalized.length - maxLength;
-      const middleIndex = Math.floor(normalized.length / 2);
-      const left = normalized.substring(0, middleIndex - excess / 2);
-      const right = normalized.substring(middleIndex + excess / 2);
-      return `${left}...${right}`;
+      const keep = Math.max(0, maxLength - 3); // reserve "..."
+      const leftLen = Math.ceil(keep / 2);
+      const rightLen = Math.floor(keep / 2);
+      const left = normalized.slice(0, leftLen);
+      const right = normalized.slice(normalized.length - rightLen);
+      return `${left}...${right}`;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 14 - 19, The truncation math currently computes
excess as normalized.length - maxLength but then adds "..." so result can exceed
maxLength; change the logic to reserve 3 chars for the ellipsis by computing
allowed = Math.max(0, maxLength - 3) (or subtract 3 from maxLength before
calculating excess), then compute excess = normalized.length - allowed and split
using integer-safe halves (use Math.floor/Math.ceil when deriving left/right
lengths from middleIndex) when building left and right (variables middleIndex,
left, right) so `${left}...${right}` never exceeds maxLength.

return normalized;
}

// Existing logic for paths with more than two segments
// ...
}
```

In this code, we added a check to see if the normalized path is longer than the `maxLength` when there are two or fewer segments. If it is, we apply a middle truncation by removing characters from the middle of the string and replacing them with an ellipsis. This ensures that the displayed path respects the `maxLength` constraint in all branches.
Comment on lines +1 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

This PR does not implement the bug fix in production code

The change only adds documentation (FIX_PROPOSAL.md). There is no modification to WelcomeRecentFiles.tsx, so the runtime behavior remains unchanged and the reported bug is still present. Please include the actual code change in the source file (and tests) in this PR.

🧰 Tools
🪛 LanguageTool

[style] ~1-~1: Consider using a different verb for a more formal wording.
Context: To fix the issue, we need to modify the `forma...

(FIX_RESOLVE)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 1 - 28, The PR only added FIX_PROPOSAL.md but
did not modify the implementation; update WelcomeRecentFiles.tsx by changing the
formatPath(path: string, maxLength: number = 60) function to normalize slashes,
enforce max-length truncation even when parts.length <= 2 by doing a
middle-truncate (replace the removed middle with "…"/"..." so final length <=
maxLength), and keep the existing behavior for paths with >2 segments; also
add/update unit tests that cover short-segment long paths and assert formatted
length <= maxLength and presence of an ellipsis.