Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into NNS1-3480/export-menu…
Browse files Browse the repository at this point in the history
…-button
  • Loading branch information
yhabib committed Dec 5, 2024
2 parents a11fb51 + 14c7679 commit d457dc0
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 53 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lib/utils/export-to-csv.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const escapeCsvValue = (value: unknown): string => {

let stringValue = String(value);

const patternForSpecialCharacters = /[",\r\n=+-@|]/;
const patternForSpecialCharacters = /[",\r\n=@|]/;
if (!patternForSpecialCharacters.test(stringValue)) {
return stringValue;
}

const formulaInjectionCharacters = "=+-@|";
const formulaInjectionCharacters = "=@|";
const characterToBreakFormula = "'";
if (formulaInjectionCharacters.includes(stringValue[0])) {
stringValue = `${characterToBreakFormula}${stringValue}`;
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/tests/lib/utils/export-to-csv.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ describe("Export to Csv", () => {
it("should prevent formula injection by prefixing with single quote", () => {
const data: TestFormulaData[] = [
{ formula: "=SUM(A1:A10)", value: 100 },
{ formula: "+1234567", value: 200 },
{ formula: "-1234567", value: 300 },
{ formula: "@SUM(A1)", value: 400 },
{ formula: "|MACRO", value: 500 },
];
Expand All @@ -91,7 +89,7 @@ describe("Export to Csv", () => {
{ id: "value", label: "value" },
];
const expected =
"formula,value\n'=SUM(A1:A10),100\n'+1234567,200\n'-1234567,300\n'@SUM(A1),400\n'|MACRO,500";
"formula,value\n'=SUM(A1:A10),100\n'@SUM(A1),400\n'|MACRO,500";
expect(convertToCsv({ data, headers })).toBe(expected);
});

Expand All @@ -104,7 +102,7 @@ describe("Export to Csv", () => {
{ id: "formula", label: "formula" },
{ id: "value", label: "value" },
];
const expected = "formula,value\n'=SUM(A1:A10),100\n\"'+1234567,12\",200";
const expected = 'formula,value\n\'=SUM(A1:A10),100\n"+1234567,12",200';
expect(convertToCsv({ data, headers })).toBe(expected);
});

Expand Down
34 changes: 29 additions & 5 deletions frontend/src/tests/workflows/Launchpad/sns-agg-page-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
"function_type": {
"NativeNervousSystemFunction": {}
}
},
{
"id": 15,
"name": "Advance SNS target version",
"description": "Proposal to advance the target version of this SNS.",
"function_type": {
"NativeNervousSystemFunction": {}
}
}
]
},
Expand Down Expand Up @@ -282,7 +290,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 799999976530394000,
"icrc1_total_supply": 799999974702594000,
"swap_params": {
"params": {
"min_participant_icp_e8s": 10000000,
Expand Down Expand Up @@ -519,6 +527,14 @@
"NativeNervousSystemFunction": {}
}
},
{
"id": 15,
"name": "Advance SNS target version",
"description": "Proposal to advance the target version of this SNS.",
"function_type": {
"NativeNervousSystemFunction": {}
}
},
{
"id": 1000,
"name": "Upgrade local_user_index canisters",
Expand Down Expand Up @@ -1086,7 +1102,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 10122996604514660,
"icrc1_total_supply": 10123995617739948,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -1816,7 +1832,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 609501443320431,
"icrc1_total_supply": 610589962133969,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -2036,6 +2052,14 @@
"NativeNervousSystemFunction": {}
}
},
{
"id": 15,
"name": "Advance SNS target version",
"description": "Proposal to advance the target version of this SNS.",
"function_type": {
"NativeNervousSystemFunction": {}
}
},
{
"id": 1000,
"name": "grant_permission",
Expand Down Expand Up @@ -2213,7 +2237,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 102799333699963400,
"icrc1_total_supply": 102895037362856290,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -2862,7 +2886,7 @@
]
],
"icrc1_fee": [100000000],
"icrc1_total_supply": 926739866561743900,
"icrc1_total_supply": 926912399675751300,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down
30 changes: 23 additions & 7 deletions frontend/src/tests/workflows/Launchpad/sns-agg-page-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
]
],
"icrc1_fee": [10000],
"icrc1_total_supply": 98205071663582060,
"icrc1_total_supply": 98205625621905220,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000278,
Expand Down Expand Up @@ -843,7 +843,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 100894224451006780,
"icrc1_total_supply": 100900495246482000,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -1373,6 +1373,14 @@
"NativeNervousSystemFunction": {}
}
},
{
"id": 15,
"name": "Advance SNS target version",
"description": "Proposal to advance the target version of this SNS.",
"function_type": {
"NativeNervousSystemFunction": {}
}
},
{
"id": 1002,
"name": "transfer DKP",
Expand Down Expand Up @@ -1538,7 +1546,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 50384594490521780,
"icrc1_total_supply": 50390095680116200,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -1752,6 +1760,14 @@
"NativeNervousSystemFunction": {}
}
},
{
"id": 15,
"name": "Advance SNS target version",
"description": "Proposal to advance the target version of this SNS.",
"function_type": {
"NativeNervousSystemFunction": {}
}
},
{
"id": 1000,
"name": "commit_proposed_batch",
Expand Down Expand Up @@ -1927,7 +1943,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 9961346334426824,
"icrc1_total_supply": 9961349260568336,
"swap_params": {
"params": {
"min_participant_icp_e8s": 100000000,
Expand Down Expand Up @@ -2320,7 +2336,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 10088713761391748,
"icrc1_total_supply": 10095855101312652,
"swap_params": {
"params": {
"min_participant_icp_e8s": 1000000000,
Expand Down Expand Up @@ -2709,7 +2725,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 12633063912717414,
"icrc1_total_supply": 12647472446219800,
"swap_params": {
"params": {
"min_participant_icp_e8s": 500000000,
Expand Down Expand Up @@ -4144,7 +4160,7 @@
]
],
"icrc1_fee": [100000],
"icrc1_total_supply": 99727028842885550,
"icrc1_total_supply": 99715900534972980,
"swap_params": {
"params": {
"min_participant_icp_e8s": 800000000,
Expand Down
Loading

0 comments on commit d457dc0

Please sign in to comment.