From b81d7473e3bb6db01faf2b42a790c5b1dccbbd83 Mon Sep 17 00:00:00 2001 From: Andy Edinborough Date: Fri, 28 Dec 2012 16:22:43 -0600 Subject: [PATCH] rewrite parseBackgroundImage to remove RegExp RegExp couldn't handle parens inside parens: linear-gradient(rgb(0,0,0),rgb(255,0,0)) --- src/Core.js | 92 ++++++++++++++++++++++++++++++++--------- tests/qunit/unit/css.js | 11 ++++- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/src/Core.js b/src/Core.js index 3f269cd..3175879 100644 --- a/src/Core.js +++ b/src/Core.js @@ -33,29 +33,81 @@ _html2canvas.Util.backgroundImage = function (src) { _html2canvas.Util.parseBackgroundImage = function (value) { var rxBackgroundImage = /([a-z\-]+)\((("[^"]+)|([^)]+))\)/i, - match, results = [], n = 0; - if(!value) { return results; } + method, definition, prefix, prefix_i, block, results = [], + c, mode = 0, numParen = 0; - while( n++ < 100 && !!(match = value.match(rxBackgroundImage)) ) { - var def = match[2], - method = match[1], - prefix = '', i; - if(def.substr( 0, 1 ) === '"') { - def = def.substr( 1, def.length-2 ); + var appendResult = function(){ + if(method) { + if(definition.substr( 0, 1 ) === '"') { + definition = definition.substr( 1, definition.length - 2 ); + } + if(method.substr( 0, 1 ) === '-' && + (prefix_i = method.indexOf( '-', 1 ) + 1) > 0) { + prefix = method.substr( 0, prefix_i); + method = method.substr( prefix_i ); + } + results.push({ + prefix: prefix, + method: method, + definition: definition, + value: block + }); } - if(method.substr( 0, 1 ) === '-' && - (i = method.indexOf( '-', 1 ) + 1) > 0) { - prefix = method.substr( 0, i); - method = method.substr( i ); + method = + prefix = + definition = + block = ''; + }; + + appendResult(); + for(var i = 0, ii = value.length; i