Skip to content

Dia: Add broken URL detection and fix#26987

Draft
Berckan wants to merge 4 commits intoraycast:mainfrom
Berckan:dia/fix-broken-url
Draft

Dia: Add broken URL detection and fix#26987
Berckan wants to merge 4 commits intoraycast:mainfrom
Berckan:dia/fix-broken-url

Conversation

@Berckan
Copy link
Copy Markdown
Contributor

@Berckan Berckan commented Apr 7, 2026

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:

  • Fix Broken URL standalone command: reads the clipboard, joins broken lines into a clean URL, and copies it back. Works silently with a HUD confirmation.
  • Inline detection in Search Dia: when a multi-line URL is pasted into the search bar, a "Fixed URL" section appears at the top with the repaired link ready to open in Dia or copy.

The detection logic (fixBrokenURL in utils.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

  • New feature (non-breaking change that adds functionality)

Test Plan

  • Copy a long URL, paste it into a text editor, add line breaks in the middle, copy that broken version
  • Open Search Dia and paste it: "Fixed URL" section should appear with the correct URL and a wand icon
  • Run "Fix Broken URL" command: clipboard should now contain the clean URL, confirmed by HUD
  • Paste a normal search query: no "Fixed URL" section should appear
  • Paste a single-line URL: only "Open URL" section should appear, not "Fixed URL"

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)
@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: dia Issues related to the dia extension platform: macOS labels Apr 7, 2026
@raycastbot
Copy link
Copy Markdown
Collaborator

raycastbot commented Apr 7, 2026

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 commands
BRANCH="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 dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 7, 2026

Greptile Summary

This PR adds a fix-url no-view command and an inline "Fixed URL" section to the Search Dia view, both aimed at repairing URLs broken across multiple lines.

  • P1 – logic divergence between fix-url.ts and utils.ts: containsBrokenURL in fix-url.ts uses a regex without a $ anchor (/^https?:\\/\\/\\S+/), so clipboard content like \"https://example.com\ This is some other text\" is accepted as a broken URL. joinBrokenURL then joins it into the malformed string \"https://example.comThis is some other text\", which is silently written to the clipboard. fixBrokenURL in utils.ts (used by the inline search path) correctly rejects this with a $ anchor — the standalone command should reuse that shared function."

Confidence Score: 4/5

Not 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

Filename Overview
extensions/dia/src/fix-url.ts New no-view command to fix broken clipboard URLs; contains a logic bug (missing $ anchor in detection regex) and duplicates logic that already exists in utils.ts.
extensions/dia/src/utils.ts Adds fixBrokenURL utility with correct $-anchored regex; logic is sound.
extensions/dia/src/components/FixedURLListItem.tsx New list item component for the inline fixed-URL suggestion; follows existing patterns.
extensions/dia/src/search.tsx Integrates fixBrokenURL and FixedURLListItem into the search view correctly.
extensions/dia/package.json Registers the new fix-url no-view command; no issues.
extensions/dia/CHANGELOG.md Not updated; a new entry is required for this PR per contribution guidelines.

Comments Outside Diff (1)

  1. extensions/dia/CHANGELOG.md, line 1 (link)

    P2 CHANGELOG entry missing

    This PR adds two user-facing features but does not include a new entry at the top of CHANGELOG.md. Per extension contribution guidelines, every PR must update the changelog.

    Rule Used: What: Ensure that CHANGELOG.md is created or updat... (source)

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: extensions/dia/CHANGELOG.md
    Line: 1
    
    Comment:
    **CHANGELOG entry missing**
    
    This PR adds two user-facing features but does not include a new entry at the top of `CHANGELOG.md`. Per extension contribution guidelines, every PR must update the changelog.
    
    
    
    **Rule Used:** What: Ensure that CHANGELOG.md is created or updat... ([source](https://app.greptile.com/review/custom-context?memory=97cd51bc-963b-43f5-acc3-9ba85fe7bb2d))
    
    How can I resolve this? If you propose a fix, please make it concise.

    Fix in Codex Fix in Cursor Fix in Claude Code

Fix All in Codex Fix All in Cursor Fix All in Claude Code

Prompt To Fix All 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.

---

This is a comment left during a code review.
Path: extensions/dia/CHANGELOG.md
Line: 1

Comment:
**CHANGELOG entry missing**

This PR adds two user-facing features but does not include a new entry at the top of `CHANGELOG.md`. Per extension contribution guidelines, every PR must update the changelog.

```suggestion
# Dia Changelog

## [Broken URL Detection and Fix] - {PR_MERGE_DATE}

- Added **Fix Broken URL** command: reads the clipboard, joins lines of a broken URL, and copies the clean version with a HUD confirmation.
- Added inline broken-URL detection in Search Dia: pasting a multi-line URL shows a "Fixed URL" section at the top of results.

```

**Rule Used:** What: Ensure that CHANGELOG.md is created or updat... ([source](https://app.greptile.com/review/custom-context?memory=97cd51bc-963b-43f5-acc3-9ba85fe7bb2d))

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(dia): add broken URL detection and ..." | Re-trigger Greptile

Comment thread extensions/dia/src/fix-url.ts Outdated
Comment on lines +7 to +11
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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

Fix in Codex Fix in Cursor Fix in Claude Code

Berckan and others added 3 commits April 7, 2026 19:05
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.
@raycastbot raycastbot added the OP is contributor The OP of the PR is a contributor of the extension label Apr 16, 2026
Copy link
Copy Markdown
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

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

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 😊

@pernielsentikaer pernielsentikaer marked this pull request as draft April 16, 2026 08:53
@pernielsentikaer pernielsentikaer self-assigned this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extension: dia Issues related to the dia extension extension fix / improvement Label for PRs with extension's fix improvements OP is contributor The OP of the PR is a contributor of the extension platform: macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants