Skip to content

Commit 6cf191f

Browse files
fix: validate glob patterns and exclude names, clarify regex escaping
- globMatch: use explicit \[ \] escaping in character class for clarity - globMatch: wrap RegExp in try/catch, fall back to substring on malformed patterns - pruneRegistry: sanitize excludeNames, filtering empty/non-string values Impact: 2 functions changed, 4 affected
1 parent 00ed205 commit 6cf191f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/embedder.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ function globMatch(filePath, pattern) {
2424
// Normalize separators to forward slashes
2525
const normalized = filePath.replace(/\\/g, '/');
2626
// Escape regex specials except glob chars
27-
let regex = pattern.replace(/\\/g, '/').replace(/[.+^${}()|[\]]/g, '\\$&');
27+
let regex = pattern.replace(/\\/g, '/').replace(/[.+^${}()|\\[\]]/g, '\\$&');
2828
// Replace ** first (matches any path segment), then * and ?
2929
regex = regex.replace(/\*\*/g, '\0');
3030
regex = regex.replace(/\*/g, '[^/]*');
3131
regex = regex.replace(/\0/g, '.*');
3232
regex = regex.replace(/\?/g, '[^/]');
33-
return new RegExp(`^${regex}$`).test(normalized);
33+
try {
34+
return new RegExp(`^${regex}$`).test(normalized);
35+
} catch {
36+
// Malformed pattern — fall back to substring match
37+
return normalized.includes(pattern);
38+
}
3439
}
3540

3641
// Lazy-load transformers (heavy, optional module)

src/registry.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export function pruneRegistry(
144144
const registry = loadRegistry(registryPath);
145145
const pruned = [];
146146
const cutoff = Date.now() - ttlDays * 24 * 60 * 60 * 1000;
147-
const excludeSet = new Set(excludeNames);
147+
const excludeSet = new Set(
148+
excludeNames.filter((n) => typeof n === 'string' && n.trim().length > 0),
149+
);
148150

149151
for (const [name, entry] of Object.entries(registry.repos)) {
150152
if (excludeSet.has(name)) continue;

0 commit comments

Comments
 (0)