Skip to content

Commit 4caeebd

Browse files
committed
fix #498: prototype pollution
* Use native promise instead of bluebird * drop support on node<8.x * reduce package size
1 parent f303866 commit 4caeebd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+10445
-2822
lines changed

browser/browser.js

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

browser/csvtojson.min.js

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

package-lock.json

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

package.json

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"hireable": null
245245
}
246246
],
247-
"version": "2.0.11",
247+
"version": "2.0.12",
248248
"keywords": [
249249
"csv",
250250
"csv parser",
@@ -262,28 +262,27 @@
262262
},
263263
"license": "MIT",
264264
"engines": {
265-
"node": ">=4.0.0"
265+
"node": ">=8.0.0"
266266
},
267267
"devDependencies": {
268-
"@types/bluebird": "^3.5.20",
269-
"@types/mocha": "^5.2.0",
270-
"@types/node": "^10.0.1",
268+
"@types/lodash.set": "^4.3.6",
269+
"@types/mocha": "^10.0.10",
270+
"@types/node": "^24.9.1",
271271
"babel-plugin-syntax-dynamic-import": "^6.18.0",
272272
"coveralls": "^3.0.1",
273273
"minimist": "^1.2.0",
274-
"mocha": "^5.1.1",
274+
"mocha": "^11.7.4",
275275
"nyc": "^11.7.3",
276276
"sinon": "^3.2.3",
277-
"ts-node": "^6.0.3",
278-
"typescript": "^2.8.3",
277+
"ts-jest": "^29.4.5",
278+
"ts-node": "^10.9.2",
279+
"typescript": "^5.9.3",
279280
"uglifyjs-webpack-plugin": "^1.2.7",
280281
"webpack": "^4.16.4",
281282
"webpack-cli": "^3.1.0"
282283
},
283284
"dependencies": {
284-
"bluebird": "^3.5.1",
285-
"lodash": "^4.17.15",
286-
"strip-bom": "^2.0.0"
285+
"lodash.set": "^4.3.2"
287286
},
288287
"nyc": {
289288
"extension": [
@@ -311,5 +310,15 @@
311310
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
312311
},
313312
"browser": "./browser/browser.js",
314-
"main": "./v2/index.js"
313+
"main": "./v2/index.js",
314+
"files": [
315+
"v1",
316+
"v2",
317+
"browser",
318+
"bin",
319+
"index.d.ts",
320+
"typings.d.ts",
321+
"LICENSE",
322+
"readme.md"
323+
]
315324
}

src/CSVError.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import CSVError from "./CSVError";
2-
import assert from "assert";
3-
describe("CSVError",()=>{
4-
it ("should toString()",()=>{
5-
})
6-
})
1+
// import CSVError from "./CSVError";
2+
// import assert from "assert";
3+
// describe("CSVError",()=>{
4+
// it ("should toString()",()=>{
5+
// })
6+
// })

src/Converter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Transform, TransformOptions, Readable } from "stream";
22
import { CSVParseParam, mergeParams } from "./Parameters";
33
import { ParseRuntime, initParseRuntime } from "./ParseRuntime";
4-
import P from "bluebird";
54
import { Processor } from "./Processor";
65
import { ProcessorLocal } from "./ProcessorLocal";
76
import { Result } from "./Result";
@@ -59,7 +58,7 @@ export class Converter extends Transform implements PromiseLike<any[]> {
5958
return this.fromStream(read);
6059
}
6160
then<TResult1 = any[], TResult2 = never>(onfulfilled?: (value: any[]) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2> {
62-
return new P((resolve, reject) => {
61+
return new Promise((resolve, reject) => {
6362
this.parseRuntime.then = {
6463
onfulfilled: (value: any[]) => {
6564
if (onfulfilled) {

src/Parameters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ export function mergeParams(params?: Partial<CSVParseParam>): CSVParseParam {
125125
for (let key in params) {
126126
if (params.hasOwnProperty(key)) {
127127
if (Array.isArray(params[key])) {
128-
defaultParam[key] = [].concat(params[key]);
128+
defaultParam[key] = [...params[key]];
129129
} else {
130130
defaultParam[key] = params[key];
131131
}
132132
}
133133
}
134134
return defaultParam;
135135
}
136-

src/ProcessFork.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Processor, ProcessLineResult } from "./Processor";
2-
import P from "bluebird"
32
import { Converter } from "./Converter";
43
import { ChildProcess } from "child_process";
54
import { CSVParseParam, mergeParams } from "./Parameters";
@@ -9,21 +8,21 @@ import { bufFromString, emptyBuffer } from "./util";
98
import CSVError from "./CSVError";
109

1110
export class ProcessorFork extends Processor {
12-
flush(): P<ProcessLineResult[]> {
13-
return new P((resolve, reject) => {
11+
flush(): Promise<ProcessLineResult[]> {
12+
return new Promise((resolve, reject) => {
1413
// console.log("flush");
1514
this.finalChunk = true;
1615
this.next = resolve;
17-
this.childProcess.stdin.end();
16+
this.childProcess.stdin?.end();
1817
// this.childProcess.stdout.on("end",()=>{
1918
// // console.log("!!!!");
2019
// this.flushResult();
2120
// })
2221
});
2322
}
24-
destroy(): P<void> {
23+
destroy(): Promise<void> {
2524
this.childProcess.kill();
26-
return P.resolve();
25+
return Promise.resolve();
2726
}
2827
childProcess: ChildProcess;
2928
inited: boolean = false;
@@ -79,14 +78,14 @@ export class ProcessorFork extends Processor {
7978
}
8079

8180
});
82-
this.childProcess.stdout.on("data", (data) => {
81+
this.childProcess.stdout?.on("data", (data) => {
8382
// console.log("stdout", data.toString());
8483
const res = data.toString();
8584
// console.log(res);
8685
this.appendBuf(res);
8786

8887
});
89-
this.childProcess.stderr.on("data", (data) => {
88+
this.childProcess.stderr?.on("data", (data) => {
9089
// console.log("stderr", data.toString());
9190
this.converter.emit("error", CSVError.fromJSON(JSON.parse(data.toString())));
9291
});
@@ -124,12 +123,12 @@ export class ProcessorFork extends Processor {
124123
// console.log("buf length",this.resultBuf.length);
125124
}
126125

127-
process(chunk: Buffer): P<ProcessLineResult[]> {
128-
return new P((resolve, reject) => {
126+
process(chunk: Buffer): Promise<ProcessLineResult[]> {
127+
return new Promise((resolve, reject) => {
129128
// console.log("chunk", chunk.length);
130129
this.next = resolve;
131130
// this.appendReadBuf(chunk);
132-
this.childProcess.stdin.write(chunk, () => {
131+
this.childProcess.stdin?.write(chunk, () => {
133132
// console.log("chunk callback");
134133
this.flushResult();
135134
});
@@ -147,4 +146,4 @@ export interface InitMessage extends Message {
147146
export interface StringMessage extends Message {
148147
value: string
149148
}
150-
export const EOM = "\x03";
149+
export const EOM = "\x03";

src/Processor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Converter } from "./Converter";
2-
import P from "bluebird";
32
import { JSONResult } from "./lineToJson";
43
import { CSVParseParam } from "./Parameters";
54
import { ParseRuntime } from "./ParseRuntime";
@@ -11,8 +10,8 @@ export abstract class Processor {
1110
this.params = converter.parseParam;
1211
this.runtime = converter.parseRuntime;
1312
}
14-
abstract process(chunk: Buffer,finalChunk?:boolean): P<ProcessLineResult[]>
15-
abstract destroy():P<void>;
16-
abstract flush(): P<ProcessLineResult[]>;
13+
abstract process(chunk: Buffer,finalChunk?:boolean): Promise<ProcessLineResult[]>
14+
abstract destroy():Promise<void>;
15+
abstract flush(): Promise<ProcessLineResult[]>;
1716
}
1817
export type ProcessLineResult = string | string[] | JSONResult;

src/ProcessorLocal.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {ProcessorLocal} from "./ProcessorLocal";
22
import { Converter } from "./Converter";
3-
import P from "bluebird";
43
import {readFileSync} from "fs";
5-
import path from "path";
6-
import assert from "assert";
4+
import * as path from "path";
5+
import assert = require("assert");
76
import { JSONResult } from "./lineToJson";
87
const dataDir=path.join(__dirname,"../test/data/");
98
describe("ProcessLocal",()=>{
@@ -37,4 +36,3 @@ describe("ProcessLocal",()=>{
3736
})
3837
})
3938
})
40-

0 commit comments

Comments
 (0)