@@ -73,6 +73,45 @@ describe('parsers', function () {
73
73
assert . strictEqual ( err_count , 1 ) ;
74
74
} ) ;
75
75
76
+ it ( 'parser error v3' , function ( ) {
77
+ var parser = new Parser ( ) ;
78
+ var reply_count = 0 ;
79
+ var err_count = 0 ;
80
+ function check_reply ( reply ) {
81
+ reply = utils . reply_to_strings ( reply ) ;
82
+ assert . strictEqual ( reply [ 0 ] , 'OK' ) ;
83
+ reply_count ++ ;
84
+ }
85
+ function check_error ( err ) {
86
+ assert . strictEqual ( err . message , 'Protocol error, got "\\n" as reply type byte' ) ;
87
+ err_count ++ ;
88
+ }
89
+ parser . send_error = check_error ;
90
+ parser . send_reply = check_reply ;
91
+
92
+ parser . execute ( new Buffer ( '*1\r\n+OK\r\n\n+zasd\r\n' ) ) ;
93
+ assert . strictEqual ( reply_count , 1 ) ;
94
+ assert . strictEqual ( err_count , 1 ) ;
95
+ } ) ;
96
+
97
+ it ( 'should handle \\r and \\n characters properly' , function ( ) {
98
+ // If a string contains \r or \n characters it will always be send as a bulk string
99
+ var parser = new Parser ( ) ;
100
+ var reply_count = 0 ;
101
+ var entries = [ 'foo\r' , 'foo\r\nbar' , '\r\nfoo' , 'foo\r\n' ] ;
102
+ function check_reply ( reply ) {
103
+ reply = utils . reply_to_strings ( reply ) ;
104
+ assert . strictEqual ( reply , entries [ reply_count ] ) ;
105
+ reply_count ++ ;
106
+ }
107
+ parser . send_reply = check_reply ;
108
+
109
+ parser . execute ( new Buffer ( '$4\r\nfoo\r\r\n$8\r\nfoo\r\nbar\r\n$5\r\n\r\n' ) ) ;
110
+ assert . strictEqual ( reply_count , 2 ) ;
111
+ parser . execute ( new Buffer ( 'foo\r\n$5\r\nfoo\r\n\r\n' ) ) ;
112
+ assert . strictEqual ( reply_count , 4 ) ;
113
+ } ) ;
114
+
76
115
it ( 'line breaks in the beginning of the last chunk' , function ( ) {
77
116
var parser = new Parser ( ) ;
78
117
var reply_count = 0 ;
0 commit comments