The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a lone pasted link lands as a url chip again
teknium1dfad5397d448
diff --git a/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsx b/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsxindex e4afd31f940..20146063f14 100644--- a/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsx+++ b/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsx@@ -35,14 +35,9 @@ afterEach(cleanup)// handler no longer consults it. On the pre-fix tree it is called once and the// payload is dropped; here it must never be called and the URL must survive.//-// Scope note: this asserts the URL lands as TEXT, not the `@url:` chip form.-// A lone pasted URL currently lands un-chipped because of a separate, older bug-// in `url-refs.ts` — `resolveExactLinkPaste` leaves the shared `URL_RE.lastIndex`-// past the first match, so the `linkifyUrls` call later in the same handler-// starts scanning after the URL and finds nothing (visible in prose pastes too:-// of two links, only the second chips). That defect is tracked separately; it is-// not this change's to fix, and asserting the chip here would fail for a reason-// that has nothing to do with the interception.+// `composerPlainText` round-trips a `@url:` chip to its directive text, so the+// assertions hold whether the link lands chipped or raw — the chip form is+// url-refs.test.ts's contract, this file's is only that the paste survives.const PR_COMMENT_URL = 'https://github.com/o/r/pull/1#issuecomment-2'const state: ChatBarState = {diff --git a/apps/desktop/src/app/chat/composer/url-refs.test.ts b/apps/desktop/src/app/chat/composer/url-refs.test.tsindex 86e3da39c1d..2b62eff2117 100644--- a/apps/desktop/src/app/chat/composer/url-refs.test.ts+++ b/apps/desktop/src/app/chat/composer/url-refs.test.ts@@ -55,6 +55,17 @@ describe('linkifyUrls', () => {it('leaves text without a scheme alone', () => {expect(linkifyUrls('example.dev/a and src/foo.ts')).toBe('example.dev/a and src/foo.ts')})++ // The paste handler runs resolveExactLinkPaste before linkifyUrls on the same+ // payload; a match left in the shared regex's lastIndex made linkifyUrls skip+ // the first link (a lone pasted URL landed as raw text) — see #112479.+ it('still chips the first link after resolveExactLinkPaste saw the same payload', () => {+ expect(resolveExactLinkPaste('https://example.dev/a/b')).toBe('https://example.dev/a/b')+ expect(linkifyUrls('https://example.dev/a/b')).toBe('@url:`https://example.dev/a/b`')++ resolveExactLinkPaste('https://a.dev and https://b.dev')+ expect(linkifyUrls('https://a.dev and https://b.dev')).toBe('@url:`https://a.dev` and @url:`https://b.dev`')+ })})describe('resolveExactLinkPaste', () => {diff --git a/apps/desktop/src/app/chat/composer/url-refs.ts b/apps/desktop/src/app/chat/composer/url-refs.tsindex 027666caf38..e0a9306acfa 100644--- a/apps/desktop/src/app/chat/composer/url-refs.ts+++ b/apps/desktop/src/app/chat/composer/url-refs.ts@@ -13,6 +13,11 @@ import { textBeforeCaret } from './text-utils'// (a filename, a version, a sentence). Brackets and quotes fence a URL in prose;// parens don't, so they stay in and an unbalanced tail is trimmed below.const URL_RE = /https?:\/\/[^\s<>[\]{}"'`]+/gi+// Anchored, non-global twin for the whole-payload check: `exec` on the shared+// global `URL_RE` would leave its `lastIndex` past the match, and `matchAll`+// inherits that offset, so the `linkifyUrls` call later in the same paste+// handler would start scanning after the link and chip nothing.+const EXACT_URL_RE = /^https?:\/\/[^\s<>[\]{}"'`]+$/iconst TYPED_URL_RE = /(?:^|\s)(https?:\/\/[^\s<>[\]{}"'`]+)$/i/** A URL at the end of a sentence carries the punctuation that ended it. */@@ -68,11 +73,7 @@ export function resolveExactLinkPaste(raw: string): string | null {const text = raw.trim()const unwrapped = text.startsWith('<') && text.endsWith('>') && text.length > 2 ? text.slice(1, -1).trim() : text- URL_RE.lastIndex = 0-- const match = URL_RE.exec(unwrapped)-- if (!match || match.index !== 0 || match[0].length !== unwrapped.length) {+ if (!EXACT_URL_RE.test(unwrapped)) {return null}