diff --git a/components/object/preview-modal.tsx b/components/object/preview-modal.tsx index 31ad295b..8a585347 100644 --- a/components/object/preview-modal.tsx +++ b/components/object/preview-modal.tsx @@ -76,9 +76,8 @@ function getPreviewMode(hasPreviewUrl: boolean, canRenderText: boolean, canRende return canRenderText ? "text" : "sandbox" } -function isPdfPreview(contentType: string, objectKey: string) { - const keyLower = objectKey.toLowerCase() - return contentType === "application/pdf" || keyLower.endsWith(".pdf") +function isPdfPreview(contentType: string) { + return contentType === "application/pdf" } function isParquetPreview(contentType: string, objectKey: string) { @@ -139,7 +138,7 @@ export function ObjectPreviewModal({ show, onShowChange, object }: ObjectPreview const isJson = normalizedContentType === "application/json" || objectKeyLower.endsWith(".json") const canRenderText = hasPreviewUrl && isSafeTextPreview(normalizedContentType, objectKey, objectSize) const canRenderImage = hasPreviewUrl && isImagePreview(normalizedContentType, objectKey) - const canRenderPdf = hasPreviewUrl && isPdfPreview(normalizedContentType, objectKey) + const canRenderPdf = hasPreviewUrl && isPdfPreview(normalizedContentType) const canRenderParquet = hasPreviewUrl && isParquetPreview(normalizedContentType, objectKey) const previewMode: PreviewMode = canRenderParquet ? "parquet" diff --git a/tests/lib/object-preview-source.test.js b/tests/lib/object-preview-source.test.js index a9fe32ed..c816dc5e 100644 --- a/tests/lib/object-preview-source.test.js +++ b/tests/lib/object-preview-source.test.js @@ -13,3 +13,14 @@ test("object preview modal falls back when standard fullscreen APIs are unavaila assert.equal(source.includes("void document.exitFullscreen().catch(() => {})"), false) assert.equal(source.includes("void container.requestFullscreen().catch(() => {})"), false) }) + +test("object preview modal only uses the PDF viewer for application/pdf content", () => { + const source = fs.readFileSync("components/object/preview-modal.tsx", "utf8") + + assert.match( + source, + /function isPdfPreview\(contentType: string\) \{\s+return contentType === "application\/pdf"\s+\}/, + ) + assert.match(source, /isPdfPreview\(normalizedContentType\)/) + assert.doesNotMatch(source, /keyLower\.endsWith\("\.pdf"\)/) +})