Skip to content

Commit 22dbec5

Browse files
committed
address review: validate sanitized IDs, fix FTS comment, early cycle detection, consistent null types
1 parent d2067e5 commit 22dbec5

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

server/src/services/multi-platform-comparison.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,19 @@ async function linkScrapedParentsToLocal(
634634

635635
const [fatherId, motherId] = person.parents;
636636
const parentLinks: Array<{
637-
parentId?: string;
637+
parentId?: string | null;
638638
externalId?: string;
639639
providerName?: string;
640640
providerUrl?: string;
641641
}> = [
642642
{
643-
parentId: fatherId ?? undefined,
643+
parentId: fatherId,
644644
externalId: scrapedData.fatherExternalId,
645645
providerName: scrapedData.fatherName,
646646
providerUrl: scrapedData.fatherUrl,
647647
},
648648
{
649-
parentId: motherId ?? undefined,
649+
parentId: motherId,
650650
externalId: scrapedData.motherExternalId,
651651
providerName: scrapedData.motherName,
652652
providerUrl: scrapedData.motherUrl,

server/src/services/path.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ function findRandomPath(sourceId: string, targetId: string): string[] | null {
138138
current = chosenAncestor;
139139
const visitedDown = new Set<string>();
140140
iterations = 0;
141+
visitedDown.add(current);
141142
while (current !== targetId && iterations < MAX_ITERATIONS) {
142143
const info = targetAncestors.get(current);
143144
if (!info || !info.parent) break;
145+
if (visitedDown.has(info.parent)) break;
146+
visitedDown.add(info.parent);
144147
current = info.parent;
145-
if (visitedDown.has(current)) break;
146-
visitedDown.add(current);
147148
pathFromAncestor.push(current);
148149
iterations++;
149150
}

server/src/utils/validation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ export function isValidUrl(url: string, requiredDomain?: string): boolean {
2727
*/
2828
export function sanitizePersonId(id: string): string {
2929
const decoded = decodeURIComponent(id);
30-
return decoded.replace(/[/\\]/g, '').replace(/\.\./g, '');
30+
const sanitized = decoded.replace(/[/\\]/g, '').replace(/\.\./g, '');
31+
if (!/^[\w:-]+$/.test(sanitized)) return '';
32+
return sanitized;
3133
}
3234

3335
/**
3436
* Escape FTS5 special operators so user input can be safely used in MATCH queries.
35-
* Removes quotes and wraps in double-quotes for phrase matching.
37+
* Removes quotes and special operator characters, then trims whitespace.
3638
*/
3739
export function sanitizeFtsQuery(query: string): string {
3840
return query.replace(/['"]/g, '').replace(/[{}()*^~]/g, '').trim();

0 commit comments

Comments
 (0)