Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Put doesn't calculate data length correctly when unicode data is given

  • Loading branch information...
commit 8954cef6f7ae675501468333937c10a5c886ce79 1 parent 5e2b881
Amjad Mohamed authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/beanstalk_client.js
View
8 lib/beanstalk_client.js
@@ -256,8 +256,14 @@ BeanstalkClient.prototype.put = function(data, priority, delay, ttr) {
ttr = 100000;
}
+ function lengthInUtf8Bytes(str) {
+ // Matches only the 10.. bytes that are non-initial characters in a multi-byte sequence.
+ var m = encodeURIComponent(str).match(/%[89ABab]/g);
+ return str.length + (m ? m.length : 0);
+ }
+
return this.command({
- command: 'put '+priority+' '+delay+' '+ttr+' '+data.toString().length+'\r\n'+data+'\r\n',
+ command: 'put '+priority+' '+delay+' '+ttr+' '+lengthInUtf8Bytes(data.toString())+'\r\n'+data+'\r\n',
expected: 'INSERTED'
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.