Dia: Add broken URL detection and fix#26987
Conversation
WHY: URLs copied from terminals, emails, or narrow viewports often get split across multiple lines, making them unusable. This adds automatic detection and repair. Adds two entry points: - "Fix Broken URL" standalone command (reads clipboard, fixes, copies back) - Inline detection in Search Dia (shows "Fixed URL" section above results)
|
Thank you for your contribution! 🎉 🔔 @tleo19 @daat21 @thomaspaulmann @loris @xmok @hetommy you might want to have a look. You can use this guide to learn how to check out the Pull Request locally in order to test it. 📋 Quick checkout commandsBRANCH="dia/fix-broken-url"
FORK_URL="https://github.com/Berckan/extensions.git"
EXTENSION_NAME="dia"
REPO_NAME="extensions"
git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run devWe're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days. |
Greptile SummaryThis PR adds a
Confidence Score: 4/5Not safe to merge as-is — the standalone fix-url command can corrupt the clipboard with malformed URLs due to the missing $ anchor. One P1 logic bug in fix-url.ts (missing $ anchor causes incorrect URL joining for mixed clipboard content) should be resolved before merging. The search/utils path is unaffected and correct. extensions/dia/src/fix-url.ts requires the regex fix or reuse of fixBrokenURL from utils.ts; CHANGELOG.md needs a new entry. Important Files Changed
|
| function containsBrokenURL(text: string): boolean { | ||
| if (!text.includes("\n") && !text.includes("\r")) return false; | ||
| const joined = text.replace(/[\r\n]+\s*/g, ""); | ||
| return /^https?:\/\/\S+/.test(joined) || /^[\w-]+:\/\/\S+/.test(joined); | ||
| } |
There was a problem hiding this comment.
Missing
$ anchor causes incorrect "fix" for mixed clipboard content
containsBrokenURL uses /^https?:\/\/\S+/ without a $ end anchor, so clipboard text like "https://example.com\nThis is some other text" passes the check. joinBrokenURL then concatenates everything into "https://example.comThis is some other text", which gets silently copied as a "fixed" URL. The fixBrokenURL in utils.ts correctly uses $ to reject this case.
Rather than patching just the regex, fix-url.ts should import and reuse fixBrokenURL from utils.ts so both code paths stay in sync:
import { fixBrokenURL } from "./utils";
import { Clipboard, closeMainWindow, showHUD, showToast, Toast } from "@raycast/api";
export default async function Command() {
try {
const clipboard = await Clipboard.readText();
if (!clipboard?.trim()) {
await showToast({ style: Toast.Style.Failure, title: "Clipboard is empty", message: "Copy a broken URL first" });
return;
}
const fixed = fixBrokenURL(clipboard.trim());
if (!fixed) {
await showToast({ style: Toast.Style.Failure, title: "No broken URL detected", message: "Clipboard doesn't contain a split URL" });
return;
}
await Clipboard.copy(fixed);
await closeMainWindow();
await showHUD("URL fixed and copied");
} catch {
await showToast({ style: Toast.Style.Failure, title: "Failed to fix URL" });
}
}Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/dia/src/fix-url.ts
Line: 7-11
Comment:
**Missing `$` anchor causes incorrect "fix" for mixed clipboard content**
`containsBrokenURL` uses `/^https?:\/\/\S+/` without a `$` end anchor, so clipboard text like `"https://example.com\nThis is some other text"` passes the check. `joinBrokenURL` then concatenates everything into `"https://example.comThis is some other text"`, which gets silently copied as a "fixed" URL. The `fixBrokenURL` in `utils.ts` correctly uses `$` to reject this case.
Rather than patching just the regex, `fix-url.ts` should import and reuse `fixBrokenURL` from `utils.ts` so both code paths stay in sync:
```typescript
import { fixBrokenURL } from "./utils";
import { Clipboard, closeMainWindow, showHUD, showToast, Toast } from "@raycast/api";
export default async function Command() {
try {
const clipboard = await Clipboard.readText();
if (!clipboard?.trim()) {
await showToast({ style: Toast.Style.Failure, title: "Clipboard is empty", message: "Copy a broken URL first" });
return;
}
const fixed = fixBrokenURL(clipboard.trim());
if (!fixed) {
await showToast({ style: Toast.Style.Failure, title: "No broken URL detected", message: "Clipboard doesn't contain a split URL" });
return;
}
await Clipboard.copy(fixed);
await closeMainWindow();
await showHUD("URL fixed and copied");
} catch {
await showToast({ style: Toast.Style.Failure, title: "Failed to fix URL" });
}
}
```
How can I resolve this? If you propose a fix, please make it concise.WHY: Raycast CI requires changelog entry for PRs
WHY: fix-url.ts had duplicated regex without $ anchor, which could corrupt clipboard by joining non-URL text into the URL string. Now both code paths use the same validated function.
pernielsentikaer
left a comment
There was a problem hiding this comment.
Hi 👋
I kinda like the idea of changing it inside the current command, but I’m not sure the new command "Fix Broken URL" is too much since it feels like more of a general thing; don’t you think so?
I converted this PR into a draft until it's ready for the review, please press the button Ready for review when it's ready and we'll have a look 😊
Summary
URLs copied from terminals, emails, or narrow viewports often get split across multiple lines, making them impossible to open directly. This PR adds automatic detection and repair:
The detection logic (
fixBrokenURLinutils.ts) checks if joining lines produces a valid URL pattern, so it only triggers when there's actually a broken URL to fix.Type of Change
Test Plan