Skip to content

Commit b16751c

Browse files
authored
Merge pull request #813 from peakon/fix/unhandledRejectionOnParseError
Avoid unhandled rejection on XML parse error
2 parents 274eea5 + 2327a09 commit b16751c

File tree

3 files changed

+126
-91
lines changed

3 files changed

+126
-91
lines changed

lib/xlsx/xform/base-xform.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
'use strict';
1+
"use strict";
22

33
const Sax = require('sax');
44
const PromiseLib = require('../../utils/promise');
55

6-
const XmlStream = require('../../utils/xml-stream');
6+
const XmlStream = require("../../utils/xml-stream");
77

88
/* 'virtual' methods used as a form of documentation */
99
/* eslint-disable class-methods-use-this */
@@ -65,25 +65,26 @@ class BaseXform {
6565
const abort = error => {
6666
// Abandon ship! Prevent the parser from consuming any more resources
6767
parser.removeAllListeners();
68+
parser.on("error", () => {}); // Ignore any parse errors from the chunk being processed
6869
stream.unpipe(parser);
6970
reject(error);
7071
};
7172

72-
parser.on('opentag', node => {
73+
parser.on("opentag", node => {
7374
try {
7475
this.parseOpen(node);
7576
} catch (error) {
7677
abort(error);
7778
}
7879
});
79-
parser.on('text', text => {
80+
parser.on("text", text => {
8081
try {
8182
this.parseText(text);
8283
} catch (error) {
8384
abort(error);
8485
}
8586
});
86-
parser.on('closetag', name => {
87+
parser.on("closetag", name => {
8788
try {
8889
if (!this.parseClose(name)) {
8990
resolve(this.model);
@@ -96,7 +97,7 @@ class BaseXform {
9697
parser.on('end', () => {
9798
resolve(this.model);
9899
});
99-
parser.on('error', error => {
100+
parser.on("error", error => {
100101
abort(error);
101102
});
102103
});
7.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)