Skip to content
Browse files

handle no data cases

  • Loading branch information...
1 parent 769350a commit 702d835a890dcb6b48b3f2ba4d56595c673e891a @Floby committed Feb 14, 2013
Showing with 9 additions and 2 deletions.
  1. +4 −0 examples/underrun.js
  2. +5 −2 lib/Tokenizer.js
View
4 examples/underrun.js
@@ -0,0 +1,4 @@
+var Tokenizer = require('../lib/Tokenizer');
+var t = new Tokenizer();
+t.end();
+
View
7 lib/Tokenizer.js
@@ -62,7 +62,10 @@ Tokenizer.prototype._tokenize = function _tokenize(data, nobuffer) {
}
// no other data is coming, we can emit what we have
if(nobuffer) {
- this._gotToken(data.substr(last_tokenized), matching[0]);
+ // when no actual data was tokenized, matching is undefined
+ if(matching) {
+ this._gotToken(data.substr(last_tokenized), matching[0]);
+ }
}
// buffer data for the next write
else {
@@ -71,7 +74,7 @@ Tokenizer.prototype._tokenize = function _tokenize(data, nobuffer) {
};
Tokenizer.prototype.end = function end(data) {
- this.write(data || '', true);
+ if(data) this.write(data, true);
this.write = noop;
this.emit('end');
};

0 comments on commit 702d835

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