Permalink
Browse files

[fix] Fix failing test for malformed inputs

  • Loading branch information...
1 parent 0266b1b commit 904dffe134ced6bcdfaa4a7fc19be996182780cf @mmalecki committed Dec 16, 2011
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/ansiparse.js
View
@@ -26,6 +26,17 @@ ansiparse = function (str) {
//
// We've matched full control code. Lets start matching formating data.
//
+
+ //
+ // "emit" matched text with correct state
+ //
+ if (matchingText) {
+ state.text = matchingText;
+ result.push(state);
+ state = {};
+ matchingText = "";
+ }
+
matchingControl = null;
matchingData = '';
}
@@ -34,6 +45,7 @@ ansiparse = function (str) {
// We failed to match anything - most likely a bad control code. We
// go back to matching regular strings.
//
+ matchingText += matchingControl + str[i];
matchingControl = null;
}
continue;
@@ -100,22 +112,14 @@ ansiparse = function (str) {
if (str[i] == '\033') {
matchingControl = str[i];
- //
- // "emit" matched text with correct state
- //
- if (matchingText) {
- state.text = matchingText;
- result.push(state);
- state = {};
- }
}
else {
matchingText += str[i];
}
}
if (matchingText) {
- state.text = matchingText;
+ state.text = matchingText + (matchingControl ? matchingControl : '');
result.push(state);
}
return result;

0 comments on commit 904dffe

Please sign in to comment.