fix: validate URL in fetchLlmsTxt
Prevent crash on invalid URLs. Changes: - Wrap URL constructor in try/catch - Return null for invalid URLs instead of throwing (cherry picked from commit 8b0acf314d0d8c84d6bf896438136e09caf8ba42)
This commit is contained in:
@@ -61,7 +61,12 @@ const llmsTxtCache = new Map<string, string | null>()
|
|||||||
|
|
||||||
/** Fetch /llms.txt for a URL's origin. Cached per origin, `null` = tried and not found. */
|
/** Fetch /llms.txt for a URL's origin. Cached per origin, `null` = tried and not found. */
|
||||||
export async function fetchLlmsTxt(url: string): Promise<string | null> {
|
export async function fetchLlmsTxt(url: string): Promise<string | null> {
|
||||||
const origin = new URL(url).origin
|
let origin: string
|
||||||
|
try {
|
||||||
|
origin = new URL(url).origin
|
||||||
|
} catch {
|
||||||
|
return null // Invalid URL
|
||||||
|
}
|
||||||
if (llmsTxtCache.has(origin)) return llmsTxtCache.get(origin)!
|
if (llmsTxtCache.has(origin)) return llmsTxtCache.get(origin)!
|
||||||
|
|
||||||
const endpoint = `${origin}/llms.txt`
|
const endpoint = `${origin}/llms.txt`
|
||||||
|
|||||||
Reference in New Issue
Block a user