diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index d0c91e3d3..dde4f5c74 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -163,19 +163,20 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) { // Get my authorID var authorId = parent.parent.pad.myUserInfo.userId; - // Rewrite apool authors with my author information - // We need to replace all new author attribs with thisSession.author, in case someone copy/pasted or otherwise inserted other peoples changes + // Sanitize authorship + // We need to replace all author attribs with thisSession.author, in case they copy/pasted or otherwise inserted other peoples changes if(apool.numToAttrib){ for (var attr in apool.numToAttrib){ - if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) authorAttr = attr + if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) authorAttr = Number(attr).toString(36) } - + // Replace all added 'author' attribs with the value of the current user var cs = Changeset.unpack(userChangeset) , iterator = Changeset.opIterator(cs.ops) , op , assem = Changeset.mergingOpAssembler(); + while(iterator.hasNext()) { op = iterator.next() if(op.opcode == '+') { @@ -183,13 +184,13 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) op.attribs.split('*').forEach(function(attrNum) { if(!attrNum) return - attr = apool.getAttrib(attrNum) + var attr = apool.getAttrib(parseInt(attrNum, 36)) if(!attr) return - if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) { + if('author' == attr[0]) { + // replace that author with the current one newAttrs += '*'+authorAttr; - // console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr) } - else newAttrs += '*'+attrNum + else newAttrs += '*'+attrNum // overtake all other attribs as is }) op.attribs = newAttrs }