Skip to content

Commit

Permalink
more parsing fixes: match VALUE and END more accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
kschzt committed Apr 11, 2011
1 parent 48496fc commit 988295e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/memcache.js
Expand Up @@ -271,14 +271,15 @@ Client.prototype.handle_get = function(buffer) {
var end_indicator_len = 3;
var result_len = 0;

if (buffer.indexOf('END') == 0) {
if (buffer.indexOf('END'+crlf) == 0) {
return [result_value, end_indicator_len + crlf_len];
} else if (buffer.indexOf('VALUE') == 0 && buffer.indexOf('END') != -1) {
first_line_len = buffer.indexOf(crlf) + crlf_len;
var end_indicator_start = buffer.indexOf('END');
result_len = end_indicator_start - first_line_len - crlf_len;
} else if (buffer.indexOf('VALUE ') == 0 && buffer.indexOf(crlf+'END'+crlf) != -1) {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var end_indicator_start = buffer.indexOf(crlf+'END'+crlf);
result_len = end_indicator_start - first_line_len;
result_value = buffer.substr(first_line_len, result_len);
return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len]
next_result_at = first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len;
return [result_value, next_result_at];
} else {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var result_len = buffer.substr(0, first_line_len).split(' ')[3];
Expand All @@ -291,12 +292,12 @@ Client.prototype.handle_get = function(buffer) {
Client.prototype.handle_stats = function(buffer){

// special case - no stats at all
if (buffer.indexOf('END') == 0){
if (buffer.indexOf('END'+crlf) == 0){
return [{}, 5];
}

// find the terminator
var idx = buffer.indexOf('\r\nEND\r\n');
var idx = buffer.indexOf(crlf+'END'+crlf);
if (idx == -1){
// wait for more data if we don't have an end yet
return null;
Expand Down

0 comments on commit 988295e

Please sign in to comment.