mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix #688 fatal exception on unmatched color stop
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
var GradientContainer = require('./gradientcontainer');
|
||||
var Color = require('./color');
|
||||
|
||||
var COLOR_STOP_REGEXP = /^(.*)\s*(\d{1,3})?(%|px)?$/;
|
||||
|
||||
function LinearGradientContainer(imageData) {
|
||||
GradientContainer.apply(this, arguments);
|
||||
this.type = this.TYPES.LINEAR;
|
||||
@ -41,13 +43,16 @@ function LinearGradientContainer(imageData) {
|
||||
this.y1 = 1;
|
||||
}
|
||||
|
||||
this.colorStops = imageData.args.slice(hasDirection ? 1 : 0).map(function(colorStop) {
|
||||
var colorStopMatch = colorStop.match(/((?:rgb|rgba)\(\d{1,3},\s\d{1,3},\s\d{1,3}(?:,\s[0-9\.]+)?\)|\w+)\s*(\d{1,3})?(%|px)?/);
|
||||
return {
|
||||
color: new Color(colorStopMatch[1]),
|
||||
stop: colorStopMatch[3] === "%" ? colorStopMatch[2] / 100 : null
|
||||
};
|
||||
}, this);
|
||||
|
||||
this.colorStops = imageData.args.slice(hasDirection ? 1 : 0)
|
||||
.map(function(colorStop) { return colorStop.match(COLOR_STOP_REGEXP);})
|
||||
.filter(function(colorStopMatch) { return !!colorStopMatch;})
|
||||
.map(function(colorStopMatch) {
|
||||
return {
|
||||
color: new Color(colorStopMatch[1]),
|
||||
stop: colorStopMatch[3] === "%" ? colorStopMatch[2] / 100 : null
|
||||
};
|
||||
});
|
||||
|
||||
if (this.colorStops[0].stop === null) {
|
||||
this.colorStops[0].stop = 0;
|
||||
|
Reference in New Issue
Block a user