From 107103bcbb7ee15fde033fdaf68d45d66d904f8b Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 6 Dec 2011 22:45:26 +0000 Subject: [PATCH] Fixes #1413: Internet Explorer colorWithCSSString crash. Syntax such as [[CPColor colorWithCSSString:@"rgba(0,0,0,0.5)"] cssString] lead to a CSS string incompatible with browsers without the CSS rgba feature. --- AppKit/CPColor.j | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/AppKit/CPColor.j b/AppKit/CPColor.j index ca9e7996a..88bdbcffe 100644 --- a/AppKit/CPColor.j +++ b/AppKit/CPColor.j @@ -480,7 +480,9 @@ function CPColorWithImages() parts[3] ? parseFloat(parts[3], 10) : 1.0 ]; - _cssString = aString; + // We can't reuse aString as _cssString because the browser might not support the `rgba` syntax, and aString might + // use it (issue #1413.) + [self _initCSSStringFromComponents]; return self; } @@ -494,18 +496,23 @@ function CPColorWithImages() { _components = components; - var hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0; - - _cssString = (hasAlpha ? "rgba(" : "rgb(") + - parseInt(_components[0] * 255.0) + ", " + - parseInt(_components[1] * 255.0) + ", " + - parseInt(_components[2] * 255.0) + - (hasAlpha ? (", " + _components[3]) : "") + ")"; + [self _initCSSStringFromComponents]; } return self; } +- (void)_initCSSStringFromComponents +{ + var hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0; + + _cssString = (hasAlpha ? "rgba(" : "rgb(") + + parseInt(_components[0] * 255.0) + ", " + + parseInt(_components[1] * 255.0) + ", " + + parseInt(_components[2] * 255.0) + + (hasAlpha ? (", " + _components[3]) : "") + ")"; +} + /* @ignore */ - (id)_initWithPatternImage:(CPImage)anImage {