Repository navigation
feat: support .md and .mdx file uploads #8995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sriramveeraghanta
wants to merge
5
commits into
preview
Choose a base branch
from
feat/file-uploads-md-mdx-support
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+162
−9
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ddb11a8
feat: support .md and .mdx file uploads
sriramveeraghanta 5adf526
fix: reject suspicious filenames and match file icons case-insensitively
sriramveeraghanta 8eeb8d7
fix: harden markdown attachment uploads
vihar 4e9c5ea
Merge remote-tracking branch 'origin/preview' into feat/file-uploads-…
sriramveeraghanta 09cc3f1
fix: limit filename rejection to the extension fallback
sriramveeraghanta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
apps/web/components/icons/attachment/attachment-icon.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { DefaultIcon, TxtIcon } from "@/components/icons/attachment"; | ||
|
|
||
| import { getFileIcon } from "./attachment-icon"; | ||
|
|
||
| describe("getFileIcon", () => { | ||
| it.each(["md", "markdown", "mdx", "MD", "MARKDOWN", "MDX"])( | ||
| "uses the text icon for the %s extension", | ||
| (extension) => { | ||
| expect(getFileIcon(extension).type).toBe(TxtIcon); | ||
| } | ||
| ); | ||
|
|
||
| it("uses the default icon for an unknown extension", () => { | ||
| expect(getFileIcon("unknown").type).toBe(DefaultIcon); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| resolve: { | ||
| tsconfigPaths: true, | ||
| }, | ||
| test: { | ||
| environment: "node", | ||
| include: ["**/*.test.{ts,tsx}"], | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { getFileMetaDataForUpload } from "./helper"; | ||
|
|
||
| const createFile = (name: string, contents: BlobPart[] = ["# Markdown"]): File => | ||
| new File(contents, name, { type: "" }); | ||
|
|
||
| const pngHeader = new Uint8Array([ | ||
| 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, | ||
| 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, 0x89, | ||
| ]); | ||
|
|
||
| describe("getFileMetaDataForUpload", () => { | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it.each(["notes.md", "notes.markdown", "notes.mdx", "NOTES.MD", "NOTES.MDX"])( | ||
| "detects %s as Markdown from its extension", | ||
| async (filename) => { | ||
| const metadata = await getFileMetaDataForUpload(createFile(filename)); | ||
|
|
||
| expect(metadata.type).toBe("text/markdown"); | ||
| } | ||
| ); | ||
|
|
||
| it.each([ | ||
| "", | ||
| ".notes.md", | ||
| "folder/notes.md", | ||
| "folder\\notes.mdx", | ||
| "notes.exe", | ||
| "notes.exe.md", | ||
| "notes.EXE.mdx", | ||
| "notes.exe.safe.md", | ||
| ])("rejects unsafe filename %s", async (filename) => { | ||
| vi.spyOn(console, "warn").mockImplementation(() => undefined); | ||
|
|
||
| const metadata = await getFileMetaDataForUpload(createFile(filename)); | ||
|
|
||
| expect(metadata.type).toBe(""); | ||
| }); | ||
|
|
||
| it.each(["notes.bin", "notes.constructor", "notes.__proto__"])( | ||
| "returns an empty type for the unsupported extension %s without a detectable signature", | ||
| async (filename) => { | ||
| const metadata = await getFileMetaDataForUpload(createFile(filename)); | ||
|
|
||
| expect(metadata.type).toBe(""); | ||
| } | ||
| ); | ||
|
|
||
| it("prefers a detected signature over the filename extension", async () => { | ||
| const metadata = await getFileMetaDataForUpload(createFile("image.md", [pngHeader])); | ||
|
|
||
| expect(metadata.type).toBe("image/png"); | ||
| }); | ||
|
|
||
| it("keeps the detected signature type when the filename only triggers a warning", async () => { | ||
| vi.spyOn(console, "warn").mockImplementation(() => undefined); | ||
|
|
||
| const metadata = await getFileMetaDataForUpload(createFile("deploy.sh.png", [pngHeader])); | ||
|
|
||
| expect(metadata.type).toBe("image/png"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.