Skip to content
Browse files

dont resume stream if resuming parser resulted in it being paused aga…

…in; throw errors in pause()/resume()
  • Loading branch information...
1 parent 25553e1 commit 66cd12216beafd0c4b6f842ec03265cf1ff8927c @dturing dturing committed
Showing with 15 additions and 3 deletions.
  1. +15 −3 lib/xml-stream.js
View
18 lib/xml-stream.js
@@ -171,13 +171,24 @@ XmlStream.prototype.preserve = function(selector, whitespace) {
// pause expat
XmlStream.prototype.pause = function() {
this._stream.pause();
- return this._parser.pause();
+ this._suspended = true;
+ if( !this._parser.pause() ) {
+ throw(new Error("Cannot pause parser: "+this._parser.getError()));
+ }
}
// resume expat
XmlStream.prototype.resume = function() {
- this._stream.resume();
- return this._parser.resume();
+ this._suspended = false;
+
+ if( !this._parser.resume() ) {
+ throw(new Error("Cannot resume parser: "+this._parser.getError()));
+ }
+
+ // resume stream only if parser hasn't been paused again
+ if( !this._suspended ) {
+ this._stream.resume();
+ }
}
// Normalizes the selector and returns the new version and its parts.
@@ -317,6 +328,7 @@ function parse() {
var self = this;
var xml = new expat.Parser('utf-8');
this._parser = xml;
+ this._suspended = false;
var stack = [];
var trace = {};
var curr = {

0 comments on commit 66cd122

Please sign in to comment.
Something went wrong with that request. Please try again.