diff --git a/index.js b/index.js index cc7a920..e9c003e 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,7 @@ mixpanel_exporter.prototype.alphabetical_sort = function(obj) { }, {}) } mixpanel_exporter.prototype.hash = function(string) { - return crypto.createHash('md5').update(string).digest('hex') + return crypto.createHash('md5').update(new Buffer(string).toString('binary')).digest('hex') } mixpanel_exporter.prototype.get_signature = function(obj) { return this.hash(_.reduce(obj, function(sig, val, key) { diff --git a/test/format.test.js b/test/format.test.js index 0b02f53..9c13938 100644 --- a/test/format.test.js +++ b/test/format.test.js @@ -82,7 +82,10 @@ describe('Methods', function() { }) describe('Hash', function() { it('should md5 a string', function() { - var md5 = require('crypto').createHash('md5').update('hash_me').digest('hex').should.equal(obj.hash('hash_me')) + var md5 = require('crypto').createHash('md5').update(new Buffer('hash_me').toString('binary')).digest('hex').should.equal(obj.hash('hash_me')) + }) + it('should md5 a string with utf-8 characters', function() { + var md5 = require('crypto').createHash('md5').update(new Buffer('®ÀÆæ中さたな').toString('binary')).digest('hex').should.equal(obj.hash('®ÀÆæ中さたな')) }) }) describe('Signature', function() {