* Check if a source matches a hostPattern entry. * Extracts the host from the source and tests it against the regex pattern. * * @param source - The marketplace source to check * @param pattern - The hostPattern entry from strictKnownMarketplaces * @returns true if the source's host matches the
(
source: MarketplaceSource,
pattern: MarketplaceSource & { source: 'hostPattern' },
)
| 276 | * @returns true if the source's host matches the pattern |
| 277 | */ |
| 278 | function doesSourceMatchHostPattern( |
| 279 | source: MarketplaceSource, |
| 280 | pattern: MarketplaceSource & { source: 'hostPattern' }, |
| 281 | ): boolean { |
| 282 | const host = extractHostFromSource(source) |
| 283 | if (!host) { |
| 284 | return false |
| 285 | } |
| 286 | |
| 287 | try { |
| 288 | const regex = new RegExp(pattern.hostPattern) |
| 289 | return regex.test(host) |
| 290 | } catch { |
| 291 | // Invalid regex - log and return false |
| 292 | logError(new Error(`Invalid hostPattern regex: ${pattern.hostPattern}`)) |
| 293 | return false |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Check if a source matches a pathPattern entry. |
no test coverage detected