From be9495d31e2aae47487e9c5b93dca2ad825cf4d0 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 26 Jul 2013 15:33:58 -0700 Subject: [PATCH] Properly clone the document for the sanity check Previously, we'd clone the data but convert it in the context of the existing dm.Document, whose nodes had pointers to elements in the old data array, not to the cloned ones. Because dm.MWReferenceNode has logic like if ( something === dataElement ), this caused the sanity check conversion to behave slightly differently compared to the real conversion that happens on save, and so a references corruption bug went unnoticed. Change-Id: I79a42ae21f91cb8eb410ae26ea638036db19e217 --- modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index 29a4b97de6..ec71157c20 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -1111,11 +1111,11 @@ ve.init.mw.ViewPageTarget.prototype.setUpSurface = function ( doc, callback ) { * (it's asynchronous, so it may still be pending when you check). */ ve.init.mw.ViewPageTarget.prototype.startSanityCheck = function () { - // We have to get the converted DOM now, before we unlock the surface and let the user edit, - // but we can defer the actual comparison + // We have to get a copy of the data now, before we unlock the surface and let the user edit, + // but we can defer the actual conversion and comparison var viewPage = this, doc = viewPage.surface.getModel().getDocument(), - data = ve.copyArray( doc.getFullData() ), + data = new ve.dm.ElementLinearData( doc.getStore().clone(), ve.copyArray( doc.getFullData() ) ), oldDom = viewPage.doc, d = $.Deferred(); @@ -1128,7 +1128,8 @@ ve.init.mw.ViewPageTarget.prototype.startSanityCheck = function () { // were ignored in the conversion. So compare each child separately. var i, len = oldDom.body.childNodes.length, - newDom = ve.dm.converter.getDomFromData( data, doc.getStore(), doc.getInternalList() ); + newDoc = new ve.dm.Document( data, undefined, doc.getInternalList() ), + newDom = ve.dm.converter.getDomFromData( newDoc.getFullData(), newDoc.getStore(), newDoc.getInternalList() ); // Explicitly unlink our full copy of the original version of the document data data = undefined;