macedigital / express-xml-bodyparser

Simple XML body parser connect/express middleware
MIT License
69 stars 27 forks source link

Create parser on every request #10

Closed fiznool closed 9 years ago

fiznool commented 9 years ago

Here's another subtle one.

I was seeing an issue where the first time a non-XML request was received, an error was being thrown, but on subsequent requests, no error was apparent.

After pouring through the xml2js source I realised that the parseString instance method isn't reusable. You need to create a new parser each time you want to call parseString. The reason for this is that the parser sets an instance variable when the underlying saxParser throws an error, and this needs to be reset in between invocations of parseString. The easiest way to achieve this is to just create a new parser per request, which is what the convenience function in the xml2js module also does.

I've added a new test case to reproduce this behaviour.

fiznool commented 9 years ago

Unfortunately this new test will break if setting async to true. No idea why! Probably best just to keep async to false for the time being :smile:

fiznool commented 9 years ago

Added a new issue to the xml2js library to track the async: true problem.

macedigital commented 9 years ago

@fiznool Release v0.2.2 is out. Just in case, I also added a note about the async issues to the README.md.

Thanks again for your support!

fiznool commented 9 years ago

No problem - glad to help out. :smile: