From fa0f614ccd9dc2a6a4695b5de7614c3c9cab6fd1 Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Wed, 7 Dec 2011 09:53:40 +1100 Subject: [PATCH] This fixes an exception when trying to parse gradient like: 'rgb(254, 254, 254) 0%, rgb(236, 236, 236) 100%' Note: This does not parse the % which would be good to delineate steps correctly, just a fix for an Exception. --- src/Generate.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Generate.js b/src/Generate.js index 3545a44..2da1024 100644 --- a/src/Generate.js +++ b/src/Generate.js @@ -31,7 +31,7 @@ html2canvas.Generate.Gradient = function(src, bounds) { canvas.height = bounds.height; - function getColors(input) { + function getColors(input) { var j = -1, color = '', chr; @@ -39,16 +39,20 @@ html2canvas.Generate.Gradient = function(src, bounds) { while( j++ < input.length ) { chr = input.charAt( j ); if (chr === ')') { - color += chr; + color += chr; steps.push( color ); color = ''; j+=2; - } else { + } else if (color || isValidColorStartChar(chr)) { color += chr; } } } + function isValidColorStartChar(c) { + return c && /[^0-9%,]/.test(c); + } + if ( tmp = src.match(/-webkit-linear-gradient\((.*)\)/) ) { position = tmp[1].split( ",", 1 )[0];