Skip to content

Commit

Permalink
1. fix bug while md5 with utf-8 characters
Browse files Browse the repository at this point in the history
2. add test-case for md5 including utf-8
  • Loading branch information
tedwu1027 authored and tedwu1027 committed Aug 29, 2014
1 parent 91cb380 commit 1f38718
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion test/format.test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 1f38718

Please sign in to comment.