Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 229e1c4

Browse files
committed
Fix null checks in ANSIParser.
1 parent df3f984 commit 229e1c4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"spectron": "3.2.0",
4646
"ts-node": "0.7.3",
4747
"tslint": "3.10.2",
48-
"typescript": "1.9.0-dev.20160525-1.0",
48+
"typescript": "1.9.0-dev.20160601-1.0",
4949
"typings": "1.0.4"
5050
},
5151
"scripts": {

src/ANSIParser.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export default class ANSIParser {
316316
let status = "handled";
317317

318318
let params: number[] = Array.isArray(rawParams) ? rawParams : [];
319-
const param: number | undefined = params[0];
319+
const param: number = params[0] || 0;
320320

321321
switch (flag) {
322322
case "A":
@@ -361,7 +361,6 @@ export default class ANSIParser {
361361
this.buffer.clear();
362362
break;
363363
case CSI.erase.toEnd:
364-
case undefined:
365364
short = "Erase Display Below (ED).";
366365

367366
this.buffer.clearToEnd();
@@ -384,7 +383,6 @@ export default class ANSIParser {
384383
this.buffer.clearRow();
385384
break;
386385
case CSI.erase.toEnd:
387-
case undefined:
388386
short = "Erase Line to Right (DECSEL).";
389387
this.buffer.clearRowToEnd();
390388
break;
@@ -438,9 +436,8 @@ export default class ANSIParser {
438436
break;
439437
}
440438

441-
while (params.length) {
442-
const sgr = params.shift();
443-
439+
while (params.length !== 0) {
440+
const sgr = params.shift()!;
444441
const attributeToSet = SGR[sgr];
445442

446443
if (!attributeToSet) {
@@ -449,7 +446,12 @@ export default class ANSIParser {
449446
const next = params.shift();
450447
if (next === 5) {
451448
const color = params.shift();
452-
this.buffer.setAttributes({[<string>attributeToSet]: colorIndex[color]});
449+
450+
if (color) {
451+
this.buffer.setAttributes({[<string>attributeToSet]: colorIndex[color]});
452+
} else {
453+
error("sgr", sgr, next, params);
454+
}
453455
} else {
454456
error("sgr", sgr, next, params);
455457
}

0 commit comments

Comments
 (0)