mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
filter invalid updates
This commit is contained in:
parent
8086d01001
commit
20d5cc69a4
2 changed files with 19 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
request = require "request"
|
||||
_ = require "underscore"
|
||||
logger = require "logger-sharelatex"
|
||||
settings = require "settings-sharelatex"
|
||||
metrics = require("metrics-sharelatex")
|
||||
|
@ -53,6 +54,8 @@ module.exports = DocumentUpdaterManager =
|
|||
return callback(err)
|
||||
|
||||
queueChange: (project_id, doc_id, change, callback = ()->)->
|
||||
allowedKeys = [ 'doc', 'op', 'v', 'dupIfSource', 'meta', 'lastV', 'hash']
|
||||
change = _.pick change, allowedKeys
|
||||
jsonChange = JSON.stringify change
|
||||
if jsonChange.indexOf("\u0000") != -1
|
||||
error = new Error("null bytes found in op")
|
||||
|
|
|
@ -122,9 +122,9 @@ describe 'DocumentUpdaterManager', ->
|
|||
describe 'queueChange', ->
|
||||
beforeEach ->
|
||||
@change = {
|
||||
"action":"removeText",
|
||||
"range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}},
|
||||
"text":"e"
|
||||
"doc":"1234567890",
|
||||
"op":["d":"test", "p":345]
|
||||
"v": 789
|
||||
}
|
||||
@rclient.rpush = sinon.stub().yields()
|
||||
@callback = sinon.stub()
|
||||
|
@ -161,3 +161,16 @@ describe 'DocumentUpdaterManager', ->
|
|||
|
||||
it "should not push the change onto the pending-updates-list queue", ->
|
||||
@rclient.rpush.called.should.equal false
|
||||
|
||||
describe "with invalid keys", ->
|
||||
beforeEach ->
|
||||
@change = {
|
||||
"op":["d":"test", "p":345]
|
||||
"version": 789 # not a valid key
|
||||
}
|
||||
@DocumentUpdaterManager.queueChange(@project_id, @doc_id, @change, @callback)
|
||||
|
||||
it "should remove the invalid keys from the change", ->
|
||||
@rclient.rpush
|
||||
.calledWith("PendingUpdates:#{@doc_id}", JSON.stringify({op:@change.op}))
|
||||
.should.equal true
|
||||
|
|
Loading…
Reference in a new issue