fix: drop non-http urls when saving scraped prospects
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfihHazrSHXgndJtSNLubJ
This commit is contained in:
parent
2b017731e5
commit
d6eca8c850
2 changed files with 17 additions and 2 deletions
|
|
@ -14,6 +14,13 @@ const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
||||||
signal?.addEventListener('abort', () => { clearTimeout(t); reject(new Error('Annulé')); }, { once: true });
|
signal?.addEventListener('abort', () => { clearTimeout(t); reject(new Error('Annulé')); }, { once: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Une page web peut tenter de faire enregistrer "javascript:…" : seules les URLs http(s) sont gardées
|
||||||
|
export function httpUrl(v) {
|
||||||
|
const s = String(v ?? '').trim();
|
||||||
|
if (!/^https?:\/\/[^\s<>"]+$/i.test(s)) return null;
|
||||||
|
try { return new URL(s).protocol.startsWith('http') ? s.slice(0, 300) : null; } catch { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
export function parseProspectLine(line) {
|
export function parseProspectLine(line) {
|
||||||
const m = /^\s*PROSPECT\s+(\{.*\})\s*$/.exec(line);
|
const m = /^\s*PROSPECT\s+(\{.*\})\s*$/.exec(line);
|
||||||
if (!m) return null;
|
if (!m) return null;
|
||||||
|
|
@ -24,8 +31,8 @@ export function parseProspectLine(line) {
|
||||||
const str = (v, max = 300) => (v == null ? null : String(v).slice(0, max));
|
const str = (v, max = 300) => (v == null ? null : String(v).slice(0, max));
|
||||||
const score = Math.max(1, Math.min(10, Math.round(Number(p.score) || 5)));
|
const score = Math.max(1, Math.min(10, Math.round(Number(p.score) || 5)));
|
||||||
return {
|
return {
|
||||||
company: str(p.company, 200), email, website: str(p.website), city: str(p.city, 100),
|
company: str(p.company, 200), email, website: httpUrl(p.website), city: str(p.city, 100),
|
||||||
sector: str(p.sector, 100), hook: str(p.hook, 400), source: str(p.source), score,
|
sector: str(p.sector, 100), hook: str(p.hook, 400), source: httpUrl(p.source), score,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,14 @@ test('flux complet : analyse → cible → prospection → modèle → envoi →
|
||||||
} finally { rmSync(s.tmp, { recursive: true, force: true }); }
|
} finally { rmSync(s.tmp, { recursive: true, force: true }); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parseProspectLine ne garde que des URLs http(s)', () => {
|
||||||
|
const p = parseProspectLine('PROSPECT {"company":"X","email":"a@b.fr","website":"javascript:alert(1)","source":"https://ok.fr/contact"}');
|
||||||
|
assert.equal(p.website, null);
|
||||||
|
assert.equal(p.source, 'https://ok.fr/contact');
|
||||||
|
assert.equal(parseProspectLine('PROSPECT {"company":"X","email":"a@b.fr","website":"https://a.fr\\" onclick=x"}').website, null);
|
||||||
|
assert.equal(parseProspectLine('PROSPECT {"company":"X","email":"a@b.fr","website":"data:text/html,x"}').website, null);
|
||||||
|
});
|
||||||
|
|
||||||
test('parseProspectLine filtre les lignes invalides', () => {
|
test('parseProspectLine filtre les lignes invalides', () => {
|
||||||
assert.equal(parseProspectLine('blabla'), null);
|
assert.equal(parseProspectLine('blabla'), null);
|
||||||
assert.equal(parseProspectLine('PROSPECT {cassé'), null);
|
assert.equal(parseProspectLine('PROSPECT {cassé'), null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue