From 1f38718ba5bb92eab5549a5c90eff62d56553559 Mon Sep 17 00:00:00 2001 From: tedwu1027 Date: Fri, 29 Aug 2014 10:26:43 +0800 Subject: [PATCH] 1. fix bug while md5 with utf-8 characters 2. add test-case for md5 including utf-8 --- index.js | 2 +- test/format.test.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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() {