Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/object-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const SAFE_TEXT_MIMES = [
"application/jsonl",
"application/ndjson",
"application/x-ndjson",
"application/sql",
"application/xml",
"text/plain",
"text/x-sql",
"text/xml",
"text/csv",
"text/markdown",
]
const SAFE_TEXT_EXTENSIONS = [".txt", ".json", ".jsonl", ".ndjson", ".xml", ".csv", ".md", ".yml", ".yaml"]
const SAFE_TEXT_EXTENSIONS = [".txt", ".json", ".jsonl", ".ndjson", ".sql", ".xml", ".csv", ".md", ".yml", ".yaml"]
const GENERIC_CONTENT_TYPES = ["", "application/octet-stream", "binary/octet-stream"]

interface ObjectPreviewOptions {
Expand Down
1 change: 1 addition & 0 deletions lib/upload-content-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function isTextualContentType(contentType) {
mime.startsWith("text/") ||
mime === "application/json" ||
mime === "application/ld+json" ||
mime === "application/sql" ||
mime === "application/xml" ||
mime.endsWith("+xml") ||
mime === "application/javascript" ||
Expand Down
1 change: 1 addition & 0 deletions lib/upload-content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function isTextualContentType(contentType: string): boolean {
mime.startsWith("text/") ||
mime === "application/json" ||
mime === "application/ld+json" ||
mime === "application/sql" ||
mime === "application/xml" ||
mime.endsWith("+xml") ||
mime === "application/javascript" ||
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/object-preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ test("existing text MIME and extension previews retain their size limit", () =>
assert.equal(isSafeTextPreview("text/plain", "fred", MAX_TEXT_PREVIEW_BYTES + 1), false)
})

test("SQL MIME types and extensions use the bounded text preview", () => {
assert.equal(isSafeTextPreview("application/sql", "schema.sql", 20), true)
assert.equal(isSafeTextPreview("text/x-sql", "schema.sql", 20), true)
assert.equal(isSafeTextPreview("application/octet-stream", "schema.sql", 20), true)
assert.equal(getObjectPreviewMode({ ...previewOptions, contentType: "application/sql", canRenderText: true }), "text")
})

test("extensionless UTF-8 text is decoded completely, including non-ASCII content", async () => {
const text = "this is a text file\n中文日志\t🙂\r\n"
assert.equal(await readObjectPreviewText(new Response(text)), text)
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/upload-content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ test("getUploadContentType infers markdown MIME type and charset when browser ty
assert.equal(await getUploadContentType(file, "readme.md"), "text/markdown; charset=utf-8")
})

test("getUploadContentType adds utf-8 charset for SQL uploads", async () => {
const file = uploadBlob(["SELECT 1;"], "schema.sql")

assert.equal(await getUploadContentType(file, "schema.sql"), "application/sql; charset=utf-8")
})

test("getUploadContentType falls back to octet-stream for unknown empty MIME types", async () => {
const file = uploadBlob(["content"], "archive.unknownext")

Expand Down