From 28ba66d98d4980a27a29444a62f88430c20544cf Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Mon, 28 May 2018 20:42:37 +0800 Subject: [PATCH] - Optimization: For `setSvgString`, if element content is not SVG, return `false` earlier (Fixes #152); thanks iuyiuy! --- editor/svgcanvas.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 2c388813..e7d5adb2 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -3632,22 +3632,23 @@ const convertToGroup = this.convertToGroup = function (elem) { } }; -// -// Function: setSvgString -// This function sets the current drawing as the input SVG XML. -// -// Parameters: -// xmlString - The SVG as XML text. -// preventUndo - Boolean (defaults to false) indicating if we want to do the -// changes without adding them to the undo stack - e.g. for initializing a -// drawing on page load. -// -// Returns: -// This function returns false if the set was unsuccessful, true otherwise. +/** +* This function sets the current drawing as the input SVG XML. +* @param {String} xmlString - The SVG as XML text. +* @param {Boolean} [preventUndo=false] - Indicates if we want to do the +* changes without adding them to the undo stack - e.g. for initializing a +* drawing on page load. +* @returns {Boolean} This function returns false if the set was +* unsuccessful, true otherwise. +*/ this.setSvgString = function (xmlString, preventUndo) { try { // convert string into XML document const newDoc = text2xml(xmlString); + if (newDoc.firstElementChild && + newDoc.firstElementChild.namespaceURI !== NS.SVG) { + return false; + } this.prepareSvg(newDoc);