csv-parser
Advanced tools
+23
-1
@@ -21,2 +21,16 @@ const { Transform } = require('stream') | ||
| const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']) | ||
| function sanitizeHeader(header) { | ||
| if (typeof header !== 'string') { | ||
| return null | ||
| } | ||
| if (DANGEROUS_KEYS.has(header)) { | ||
| return null | ||
| } | ||
| return header | ||
| } | ||
| class CsvParser extends Transform { | ||
@@ -159,4 +173,12 @@ constructor (opts = {}) { | ||
| this.state.first = false | ||
| this.headers = cells.map((header, index) => mapHeaders({ header, index })) | ||
| this.headers = cells.map((header, index) => { | ||
| const mapped = mapHeaders({ header, index }) | ||
| if (mapped === null) { | ||
| return null | ||
| } | ||
| return sanitizeHeader(mapped) | ||
| }) | ||
| this.emit('headers', this.headers) | ||
@@ -163,0 +185,0 @@ return |
+1
-1
| { | ||
| "name": "csv-parser", | ||
| "version": "3.2.0", | ||
| "version": "3.2.1", | ||
| "description": "Streaming CSV parser that aims for maximum speed as well as compatibility with the csv-spectrum test suite", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
29926
1.28%387
4.31%