From: Ray Glover Date: Fri, 14 Aug 2015 15:59:01 +0000 (+0100) Subject: Make parsing a more robust in the face of IE11 X-Git-Tag: 2.1.0~3^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=65f9900d5e98272a1c0c0d9ca922666603110804;p=svg.js.git Make parsing a more robust in the face of IE11 which doesn't use commas (',') to delimit matrix elements. see also: http://www.w3.org/TR/SVG11/coords.html#SVGGlobalTransformAttribute --- diff --git a/src/helpers.js b/src/helpers.js index 7fe9f7a..f3a36b9 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -72,7 +72,7 @@ function stringToMatrix(source) { source = source .replace(SVG.regex.whitespace, '') .replace(SVG.regex.matrix, '') - .split(',') + .split(SVG.regex.matrixElements) // convert string values to floats and convert to a matrix-formatted object return arrayToMatrix( diff --git a/src/regex.js b/src/regex.js index d08dc7b..a6ffb98 100644 --- a/src/regex.js +++ b/src/regex.js @@ -14,6 +14,9 @@ SVG.regex = { // Parse matrix wrapper , matrix: /matrix\(|\)/g + + // Elements of a matrix +, matrixElements: /,*\s+|,/ // Whitespace , whitespace: /\s/g diff --git a/src/transform.js b/src/transform.js index 2023439..c1afd73 100644 --- a/src/transform.js +++ b/src/transform.js @@ -130,7 +130,7 @@ SVG.extend(SVG.Element, { .split(/\)\s*/).slice(0,-1).map(function(str){ // generate key => value pairs var kv = str.trim().split('(') - return [kv[0], kv[1].split(',').map(function(str){ return parseFloat(str) })] + return [kv[0], kv[1].split(SVG.regex.matrixElements).map(function(str){ return parseFloat(str) })] }) // calculate every transformation into one matrix .reduce(function(matrix, transform){