File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,15 @@ module.exports = function(bodyParser) {
27
27
if ( typeof req . body !== 'string' ) { return next ( ) ; }
28
28
29
29
// Then, parse as XML.
30
- const parser = new xml2js . Parser ( options . xmlParseOptions ) ;
30
+ const xmlParseOptions = {
31
+ ...options . xmlParseOptions ,
32
+ // Always opt-in to async mode.
33
+ async : true
34
+ } ;
35
+ const parser = new xml2js . Parser ( xmlParseOptions ) ;
36
+
37
+ // In some cases xml2js.Parser parseString() can throw an error after executing the callback.
38
+
31
39
parser . parseString ( req . body , function ( err , xml ) {
32
40
if ( err ) {
33
41
err . status = 400 ;
Original file line number Diff line number Diff line change @@ -93,7 +93,6 @@ describe('XML Body Parser', function() {
93
93
94
94
it ( 'should ignore non-XML' , function ( done ) {
95
95
createServer ( ) ;
96
-
97
96
request ( app )
98
97
. post ( '/' )
99
98
. set ( 'Content-Type' , 'text/plain' )
@@ -109,4 +108,14 @@ describe('XML Body Parser', function() {
109
108
. send ( '<invalid-xml>' )
110
109
. expect ( 400 , done ) ;
111
110
} ) ;
111
+
112
+ it ( 'should not throw an exception after the callback is returned' , function ( done ) {
113
+ // Guards against https://github.com/Leonidas-from-XIV/node-xml2js/issues/400
114
+ createServer ( ) ;
115
+ request ( app )
116
+ . post ( '/' )
117
+ . set ( 'Content-Type' , 'text/xml' )
118
+ . send ( 'x<foo>test</foo><bar>test</bar></data>' )
119
+ . expect ( 400 , done ) ;
120
+ } )
112
121
} ) ;
You can’t perform that action at this time.
0 commit comments