Skip to content

Commit 14bfcb7

Browse files
waleedlatif1claude
andcommitted
fix(knowledge): case-insensitive scheme checks for fileUrl
Boundary schema accepted uppercase schemes (e.g. HTTPS://, DATA:) via the case-insensitive http regex, but the processor's case-sensitive startsWith('data:') / startsWith('http') / startsWith('https://') checks rejected them with a confusing "Unsupported fileUrl scheme" error. Aligns processor checks to the schema using case-insensitive regex per RFC 3986 §3.1. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2b06b80 commit 14bfcb7

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

apps/sim/lib/api/contracts/knowledge/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const knowledgeDocumentFileUrlSchema = z
3434
.string()
3535
.min(1, 'File URL is required')
3636
.refine(
37-
(value) => value.startsWith('data:') || /^https?:\/\//i.test(value),
37+
(value) => /^data:/i.test(value) || /^https?:\/\//i.test(value),
3838
'File URL must be a data: URI or an http(s):// URL'
3939
)
4040

apps/sim/lib/knowledge/documents/document-processor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ async function handleFileForOCR(
315315
userId?: string,
316316
workspaceId?: string | null
317317
) {
318-
const isExternalHttps = fileUrl.startsWith('https://') && !isInternalFileUrl(fileUrl)
318+
const isExternalHttps = /^https:\/\//i.test(fileUrl) && !isInternalFileUrl(fileUrl)
319319

320320
if (isExternalHttps) {
321321
if (mimeType === 'application/pdf') {
@@ -385,14 +385,14 @@ async function downloadFileWithTimeout(fileUrl: string): Promise<Buffer> {
385385
}
386386

387387
async function downloadFileForBase64(fileUrl: string): Promise<Buffer> {
388-
if (fileUrl.startsWith('data:')) {
388+
if (/^data:/i.test(fileUrl)) {
389389
const [, base64Data] = fileUrl.split(',')
390390
if (!base64Data) {
391391
throw new Error('Invalid data URI format')
392392
}
393393
return Buffer.from(base64Data, 'base64')
394394
}
395-
if (fileUrl.startsWith('http')) {
395+
if (/^https?:\/\//i.test(fileUrl)) {
396396
return downloadFileWithTimeout(fileUrl)
397397
}
398398
throw new Error('Unsupported fileUrl scheme: only data: URIs and http(s):// URLs are allowed')
@@ -782,9 +782,9 @@ async function parseWithFileParser(fileUrl: string, filename: string, mimeType:
782782
let content: string
783783
let metadata: FileParseMetadata = {}
784784

785-
if (fileUrl.startsWith('data:')) {
785+
if (/^data:/i.test(fileUrl)) {
786786
content = await parseDataURI(fileUrl, filename, mimeType)
787-
} else if (fileUrl.startsWith('http')) {
787+
} else if (/^https?:\/\//i.test(fileUrl)) {
788788
const result = await parseHttpFile(fileUrl, filename, mimeType)
789789
content = result.content
790790
metadata = result.metadata || {}

0 commit comments

Comments
 (0)