fix: normalize bare URLs in capture flow

This commit is contained in:
2026-06-05 12:29:19 +08:00
parent 56ef211418
commit 6d15639b41
11 changed files with 139 additions and 27 deletions
+26 -1
View File
@@ -155,6 +155,13 @@ async function runReadyScenario(cdp, url) {
await clickText(cdp, '.modal-actions .btn', 'Разложить')
await waitForGone(cdp, '.modal-overlay')
await assertEval(cdp, `!document.querySelector('.inbox-screen')?.innerText.includes('example.test')`, 'inbox: assigned link leaves inbox')
await setClipboardText(cdp, 'mirv.top')
await clickText(cdp, '.inbox-header .btn', 'Вставить из буфера')
await assertText(cdp, 'mirv.top', 'inbox: bare domain captured as URL')
await clickInboxItemButton(cdp, 'mirv.top', 'Открыть')
await assertEval(cdp, `window.__VERSTAK_GUI_SMOKE__.state.openedUrls.includes('https://mirv.top')`, 'inbox: bare domain opens normalized URL')
await clickInboxItemButton(cdp, 'mirv.top', 'Удалить')
await clickText(cdp, '.overlay .btn', 'Удалить')
await emitDroppedFiles(cdp, ['/tmp/smoke-drop-folder'])
await assertText(cdp, 'smoke-drop-folder', 'inbox: dropped folder captured')
await assertText(cdp, 'Перетаскивание', 'inbox: dropped source visible')
@@ -833,6 +840,23 @@ function wailsMockSource() {
try { return new URL(value).hostname; } catch { return ''; }
}
function normalizeURL(value) {
const raw = String(value || '').trim();
if (!raw || /[\s]/.test(raw) || raw.includes('@')) return '';
try {
const parsed = new URL(raw);
return (parsed.protocol === 'http:' || parsed.protocol === 'https:') && parsed.hostname ? raw : '';
} catch {
try {
const withScheme = `https://${raw}`;
const parsed = new URL(withScheme);
return parsed.hostname && parsed.hostname.includes('.') ? withScheme : '';
} catch {
return '';
}
}
}
function inboxDTO(node) {
return {
...node,
@@ -960,7 +984,8 @@ function wailsMockSource() {
CaptureClipboardTextWithContext: async (contextJSON) => {
const text = String(window.__VERSTAK_GUI_SMOKE_CLIPBOARD__ || '').trim();
if (!text) throw new Error('clipboard is empty');
if (/^https?:\\/\\//.test(text)) return App.CaptureURLWithContext(text, '', 'clipboard_button', contextJSON);
const normalizedURL = normalizeURL(text);
if (normalizedURL) return App.CaptureURLWithContext(normalizedURL, '', 'clipboard_button', contextJSON);
return App.CaptureTextWithContext(text, 'clipboard_button', contextJSON);
},
ResolveInboxNode: async (nodeId, targetParentId) => {