mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
fix utf8 encoding in sha1 hash
This commit is contained in:
parent
62165ddeab
commit
5eb339e525
2 changed files with 11 additions and 8 deletions
|
@ -185,5 +185,8 @@ module.exports = RedisManager =
|
|||
return JSON.parse(ranges)
|
||||
|
||||
_computeHash: (docLines) ->
|
||||
# use sha1 checksum of doclines to detect data corruption
|
||||
return crypto.createHash('sha1').update(docLines).digest('hex')
|
||||
# use sha1 checksum of doclines to detect data corruption.
|
||||
#
|
||||
# note: must specify 'utf8' encoding explicitly, as the default is
|
||||
# binary in node < v5
|
||||
return crypto.createHash('sha1').update(docLines, 'utf8').digest('hex')
|
||||
|
|
|
@ -37,10 +37,10 @@ describe "RedisManager", ->
|
|||
|
||||
describe "getDoc", ->
|
||||
beforeEach ->
|
||||
@lines = ["one", "two", "three"]
|
||||
@lines = ["one", "two", "three", "これは"] # include some utf8
|
||||
@jsonlines = JSON.stringify @lines
|
||||
@version = 42
|
||||
@hash = crypto.createHash('sha1').update(@jsonlines).digest('hex')
|
||||
@hash = crypto.createHash('sha1').update(@jsonlines,'utf8').digest('hex')
|
||||
@ranges = { comments: "mock", entries: "mock" }
|
||||
@json_ranges = JSON.stringify @ranges
|
||||
@rclient.get = sinon.stub()
|
||||
|
@ -200,10 +200,10 @@ describe "RedisManager", ->
|
|||
@rclient.eval = sinon.stub()
|
||||
@RedisManager.getDocVersion = sinon.stub()
|
||||
|
||||
@lines = ["one", "two", "three"]
|
||||
@lines = ["one", "two", "three", "これは"]
|
||||
@ops = [{ op: [{ i: "foo", p: 4 }] },{ op: [{ i: "bar", p: 8 }] }]
|
||||
@version = 42
|
||||
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines)).digest('hex')
|
||||
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines),'utf8').digest('hex')
|
||||
@ranges = { comments: "mock", entries: "mock" }
|
||||
|
||||
@rclient.exec = sinon.stub().callsArg(0, null, [@hash])
|
||||
|
@ -323,9 +323,9 @@ describe "RedisManager", ->
|
|||
@rclient.sadd = sinon.stub().yields()
|
||||
@rclient.del = sinon.stub()
|
||||
@rclient.eval = sinon.stub()
|
||||
@lines = ["one", "two", "three"]
|
||||
@lines = ["one", "two", "three", "これは"]
|
||||
@version = 42
|
||||
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines)).digest('hex')
|
||||
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines),'utf8').digest('hex')
|
||||
@rclient.exec = sinon.stub().callsArgWith(0, null, [@hash])
|
||||
@ranges = { comments: "mock", entries: "mock" }
|
||||
|
||||
|
|
Loading…
Reference in a new issue