Repository navigation
fix(utils): preserve CSV fields and data URI contents #10198
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
JunaidAhamed-7777
wants to merge
1
commit into
makeplane:preview
Choose a base branch
from
JunaidAhamed-7777:fix/csv-download-integrity
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.
Open
Changes from all commits
Commits
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
There are no files selected for viewing
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,67 @@ | ||
| /** | ||
| * 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 { csvDownload } from "./file"; | ||
|
|
||
| vi.mock("@plane/constants", () => ({ API_BASE_URL: "" })); | ||
|
|
||
| afterEach(() => vi.unstubAllGlobals()); | ||
|
|
||
| async function download(data: string[][] | Record<string, string>) { | ||
| const link = { href: "", download: "", click: vi.fn() }; | ||
| const appendChild = vi.fn(); | ||
| const removeChild = vi.fn(); | ||
| vi.stubGlobal("document", { | ||
| createElement: vi.fn(() => link), | ||
| body: { appendChild, removeChild }, | ||
| }); | ||
| csvDownload(data, "export"); | ||
| expect(link.download).toBe("export.csv"); | ||
| expect(link.click).toHaveBeenCalledOnce(); | ||
| expect(appendChild).toHaveBeenCalledWith(link); | ||
| expect(removeChild).toHaveBeenCalledWith(link); | ||
| return (await fetch(link.href)).text(); | ||
| } | ||
|
|
||
| describe("csvDownload", () => { | ||
| it("keeps ordinary object headers and values", async () => { | ||
| expect(await download({ Title: "Build", "Secret key": "fake-token" })).toBe("Title,Secret key\nBuild,fake-token"); | ||
| }); | ||
| it("preserves a hash and subsequent secret-key columns", async () => { | ||
| expect(await download({ Title: "Build #42", "Secret key": "fake-token" })).toBe( | ||
| "Title,Secret key\nBuild #42,fake-token" | ||
| ); | ||
| }); | ||
| it("quotes commas so user labels do not shift columns", async () => { | ||
| expect(await download({ Title: "Build, deploy", "Secret key": "fake-token" })).toBe( | ||
| 'Title,Secret key\n"Build, deploy",fake-token' | ||
| ); | ||
| }); | ||
| it("doubles quotes in quoted cells", async () => { | ||
| expect(await download([['A "quoted" label', "value"]])).toBe('"A ""quoted"" label",value'); | ||
| }); | ||
| it.each(["\n", "\r", "\r\n"])("quotes embedded %j line endings", async (separator) => { | ||
| expect(await download([[`first${separator}second`, "value"]])).toBe(`"first${separator}second",value`); | ||
| }); | ||
| it("preserves Unicode and URI-special characters", async () => { | ||
| expect(await download([["日本語 # % & ? + =", "last"]])).toBe("日本語 # % & ? + =,last"); | ||
| }); | ||
| it("escapes object headers as well as values", async () => { | ||
| expect(await download({ "a,b": 'c"d' })).toBe('"a,b"\n"c""d"'); | ||
| }); | ||
| it("preserves empty cells and input data", async () => { | ||
| const rows = [ | ||
| ["", "last"], | ||
| ["first", ""], | ||
| ]; | ||
| expect(await download(rows)).toBe(",last\nfirst,"); | ||
| expect(rows).toEqual([ | ||
| ["", "last"], | ||
| ["first", ""], | ||
| ]); | ||
| }); | ||
| }); |
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,20 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import path from "node:path"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| include: ["src/**/*.test.ts"], | ||
| environment: "node", | ||
| }, | ||
| resolve: { | ||
| alias: { | ||
| "@plane/constants": path.resolve(import.meta.dirname, "../constants/src/index.ts"), | ||
| }, | ||
| }, | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: makeplane/plane
Length of output: 2416
Script executed:
Repository: makeplane/plane
Length of output: 30278
Script executed:
Repository: makeplane/plane
Length of output: 17274
Web query:
OWASP CSV injection formula cell quoted CSV field leading equals sign Excel evaluates formula even when field is quotedResult:
Neutralize formula-leading cells in
csvDownloadbefore quoting.Quoting keeps a label such as
=HYPERLINK(...)in one cell, and spreadsheets still evaluate it. A token label that referencesD2can then send the secret key to an external URL when a user clicks the link. Prefix cells that start with=,+,-, or@, assanitize_csv_valuedoes on the server.