Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing hashing issue with non-ASCII characters

  • Loading branch information...
commit 722cbcce6a6e34e3364133c66981dd8200b6d097 1 parent 970824d
@infynyxx infynyxx authored
View
2  lib/sailthru_util.js
@@ -22,7 +22,7 @@
SailthruUtil.md5 = function(data) {
var md5;
md5 = crypto.createHash('md5');
- md5.update(data);
+ md5.update(data, 'utf8');
return md5.digest('hex');
};
View
2  src/sailthru_util.coffee
@@ -11,7 +11,7 @@ exports.SailthruUtil = class SailthruUtil
@md5: (data) ->
md5 = crypto.createHash('md5')
- md5.update data
+ md5.update data, 'utf8'
return md5.digest 'hex'
@extractParamValues: (params) ->
View
23 test/test_sailthru_util.coffee
@@ -1,5 +1,6 @@
{SailthruUtil} = require '../lib/sailthru_util'
{testCase} = require 'nodeunit'
+{exec, spawn} = require 'child_process'
exports.testExtractParams = (test) ->
test.expect 4
@@ -89,3 +90,25 @@ exports.testGetSignatureHash = (test) ->
test.done()
+exports.testMd5 = (test) ->
+ test.expect 1
+ data1 = 'simple_text'
+ hash1 = SailthruUtil.md5 data1
+ cmd1 = "python -c 'import hashlib; print hashlib.md5(\"" + data1 + "\").hexdigest()'"
+
+ exec1 = exec cmd1, (error, stdout, stderr) ->
+ test.equal stdout.trim(), hash1
+ #test.done()
+
+ data2 = "नमस्ते विश्व"
+ hash2 = SailthruUtil.md5 data2
+
+ cmd2 = "python -c 'import hashlib; print hashlib.md5(\"" + data2 + "\").hexdigest()'"
+
+ exec2 = exec cmd2, (error, stdout, stderr) ->
+ test.equal stdout.trim(), hash2
+
+ exec2.on 'exit', (code) ->
+ test.done()
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.