Only encode ranges if option passed

This commit is contained in:
Alasdair Smith 2017-09-21 14:23:16 +01:00
parent 9f503f1e9f
commit aa6e0d0d69
2 changed files with 25 additions and 26 deletions

View file

@ -80,13 +80,13 @@ module.exports = Router =
Router._handleError null, err, client, "leaveProject"
client.on "joinDoc", (doc_id, fromVersion, callback) ->
client.on "joinDoc", (doc_id, options, fromVersion, callback) ->
# fromVersion is optional
if typeof fromVersion == "function"
callback = fromVersion
fromVersion = -1
WebsocketController.joinDoc client, doc_id, fromVersion, (err, args...) ->
WebsocketController.joinDoc client, doc_id, options, fromVersion, (err, args...) ->
if err?
Router._handleError callback, err, client, "joinDoc", {doc_id, fromVersion}
else

View file

@ -80,7 +80,7 @@ module.exports = WebsocketController =
callback()
, WebsocketController.FLUSH_IF_EMPTY_DELAY
joinDoc: (client, doc_id, fromVersion = -1, callback = (error, doclines, version, ops, ranges) ->) ->
joinDoc: (client, doc_id, options, fromVersion = -1, callback = (error, doclines, version, ops, ranges) ->) ->
metrics.inc "editor.join-doc"
Utils.getClientAttributes client, ["project_id", "user_id"], (error, {project_id, user_id}) ->
return callback(error) if error?
@ -101,29 +101,28 @@ module.exports = WebsocketController =
logger.err {err, project_id, doc_id, fromVersion, line, client_id: client.id}, "error encoding line uri component"
return callback(err)
escapedLines.push line
if ranges.comments
escapedComments = []
for comment in ranges.comments
try
comment.op.c = unescape(encodeURIComponent(comment.op.c))
catch err
logger.err {err, project_id, doc_id, fromVersion, comment, client_id: client.id}, "error encoding comment uri component"
return callback(err)
escapedComments.push comment
ranges.comments = escapedComments
if ranges.changes
escapedChanges = []
for change in ranges.changes
try
change.op.i = unescape(encodeURIComponent(change.op.i)) if change.op.i
change.op.d = unescape(encodeURIComponent(change.op.d)) if change.op.d
catch err
logger.err {err, project_id, doc_id, fromVersion, change, client_id: client.id}, "error encoding change uri component"
return callback(err)
escapedChanges.push change
ranges.changes = escapedChanges
if options.encodeRanges
if ranges.comments
escapedComments = []
for comment in ranges.comments
try
comment.op.c = unescape(encodeURIComponent(comment.op.c))
catch err
logger.err {err, project_id, doc_id, fromVersion, comment, client_id: client.id}, "error encoding comment uri component"
return callback(err)
escapedComments.push comment
ranges.comments = escapedComments
if ranges.changes
escapedChanges = []
for change in ranges.changes
try
change.op.i = unescape(encodeURIComponent(change.op.i)) if change.op.i
change.op.d = unescape(encodeURIComponent(change.op.d)) if change.op.d
catch err
logger.err {err, project_id, doc_id, fromVersion, change, client_id: client.id}, "error encoding change uri component"
return callback(err)
escapedChanges.push change
ranges.changes = escapedChanges
AuthorizationManager.addAccessToDoc client, doc_id
client.join(doc_id)