From: Aleksander Ɓukasz Date: Mon, 30 Dec 2013 13:11:12 +0000 (+0100) Subject: editor: handle invalid xml sent as a wlxml document X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/82a99e22c8cfc4e50bc15307c818878a261ca1bb editor: handle invalid xml sent as a wlxml document --- diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 4a9bc72..db17955 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -2,11 +2,16 @@ define([ 'libs/jquery', './dialog', 'wlxml/wlxml', - 'wlxml/extensions/list/list' -], function($, Dialog, wlxml, listExtension) { + 'wlxml/extensions/list/list', + 'fnpjs/logging/logging', +], function($, Dialog, wlxml, listExtension, logging) { 'use strict'; -/* global gettext */ +/* global gettext, alert */ + +var logger = logging.getLogger('editor.modules.data'), + stubDocument = '
' + gettext('This is an empty document.') + '
'; + return function(sandbox) { @@ -14,7 +19,14 @@ return function(sandbox) { var document_version = sandbox.getBootstrappedData().version; var history = sandbox.getBootstrappedData().history; - var wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document); + var wlxmlDocument; + try { + wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document); + } catch(e) { + logger.exception(e); + alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO + wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument); + } wlxmlDocument.registerExtension(listExtension); sandbox.getPlugins().forEach(function(plugin) {