* Check if a source matches a pathPattern entry. * Tests the source's .path (file and directory sources only) against the regex pattern. * * @param source - The marketplace source to check * @param pattern - The pathPattern entry from strictKnownMarketplaces * @returns true if the source's path
(
source: MarketplaceSource,
pattern: MarketplaceSource & { source: 'pathPattern' },
)
| 303 | * @returns true if the source's path matches the pattern |
| 304 | */ |
| 305 | function doesSourceMatchPathPattern( |
| 306 | source: MarketplaceSource, |
| 307 | pattern: MarketplaceSource & { source: 'pathPattern' }, |
| 308 | ): boolean { |
| 309 | // Only file and directory sources have a .path to match against |
| 310 | if (source.source !== 'file' && source.source !== 'directory') { |
| 311 | return false |
| 312 | } |
| 313 | |
| 314 | try { |
| 315 | const regex = new RegExp(pattern.pathPattern) |
| 316 | return regex.test(source.path) |
| 317 | } catch { |
| 318 | logError(new Error(`Invalid pathPattern regex: ${pattern.pathPattern}`)) |
| 319 | return false |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Get hosts from hostPattern entries in the allowlist. |
no test coverage detected