Skip to content

Commit 1d19460

Browse files
authored
Merge pull request #285 from mrodrig/fix-csv-injection-patch
Fix csv injection patch
2 parents dd154d6 + fbbe360 commit 1d19460

7 files changed

Lines changed: 116 additions & 75 deletions

File tree

.github/workflows/automated-tests-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ubuntu-latest]
12-
node: [18, 20, 22]
12+
node: [20, 22, 24]
1313

1414
steps:
1515
- uses: actions/checkout@v3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Returns the CSV `string` or rejects with an `Error` if there was an issue.
197197
* Note: If selected, values will be converted using `toLocaleString()` rather than `toString()`
198198
* `wrapBooleans` - Boolean - Should boolean values be wrapped in wrap delimiters to prevent Excel from converting them to Excel's TRUE/FALSE Boolean values.
199199
* Default: `false`
200-
* `preventCsvInjection` - Boolean - Should CSV injection be prevented by left trimming these characters: Equals (=), Plus (+), Minus (-), At (@), Tab (0x09), Carriage return (0x0D).
200+
* `preventCsvInjection` - Boolean - Should CSV injection be prevented by left trimming these characters, including when they appear after leading spaces: Equals (=), Plus (+), Minus (-), At (@), Tab (0x09), Carriage return (0x0D).
201201
* Default: `false`
202202

203203

@@ -324,4 +324,4 @@ $ npm run coverage
324324
* `json2csv test.json -o output.csv -W -k arrayOfStrings -o output.csv`
325325
* Empty field value option (as of 3.1.0)
326326
* TypeScript typings included (as of 3.4.0) - thanks to [@GabrielCastro](https://github.com/GabrielCastro)!
327-
* Synchronous use case support (as of 5.0.0) - thanks to [@Nokel81](https://github.com/Nokel81)
327+
* Synchronous use case support (as of 5.0.0) - thanks to [@Nokel81](https://github.com/Nokel81)

package-lock.json

Lines changed: 86 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"name": "json-2-csv",
77
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
8-
"version": "5.5.10",
8+
"version": "5.5.11",
99
"homepage": "https://mrodrig.github.io/json-2-csv",
1010
"repository": {
1111
"type": "git",
@@ -40,8 +40,8 @@
4040
"cli"
4141
],
4242
"dependencies": {
43-
"deeks": "3.1.0",
44-
"doc-path": "4.1.1"
43+
"deeks": "3.2.1",
44+
"doc-path": "4.1.4"
4545
},
4646
"devDependencies": {
4747
"@types/mocha": "10.0.1",
@@ -60,4 +60,4 @@
6060
"node": ">= 16"
6161
},
6262
"license": "MIT"
63-
}
63+
}

src/json2csv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export const Json2Csv = function (options: DefaultJson2CsvOptions) {
407407
if (Array.isArray(fieldValue)) {
408408
return fieldValue.map(preventCsvInjection);
409409
} else if (typeof fieldValue === 'string' && !utils.isNumber(fieldValue)) {
410-
return fieldValue.replace(/^[=+\-@\t\r]+/g, '');
410+
return fieldValue.replace(/^[ \t\r]*[=+\-@\t\r]+/g, '');
411411
}
412412
return fieldValue;
413413
}

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ interface SharedConverterOptions {
5757

5858
/**
5959
* Should CSV injection be prevented by left trimming these characters:
60-
* Equals (=), Plus (+), Minus (-), At (@), Tab (0x09), Carriage return (0x0D).
60+
* Equals (=), Plus (+), Minus (-), At (@), Tab (0x09), Carriage return (0x0D),
61+
* including when they appear after leading spaces.
6162
* @default false
6263
*/
6364
preventCsvInjection?: boolean;

0 commit comments

Comments
 (0)