Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix out-of-range alpha values in rgba() strings

  • Loading branch information...
commit 3678371d48ae0bf49e608f3a3fda421d9d308f37 1 parent 1cafabd
@padolsey padolsey authored
Showing with 7 additions and 1 deletion.
  1. +1 −0  CHANGELOG
  2. +1 −1  src/color.js
  3. +5 −0 test/color-spec.js
View
1  CHANGELOG
@@ -9,6 +9,7 @@ v0.4.1
Video and Audio.
* Fixed examples to be in line with the documentation.
* Fix out-of-range hsl color values
+* Fix out-of-range alpha values when parsing rgba() strings
v0.4.0 / 2012-10-03
-------------------
View
2  src/color.js
@@ -479,7 +479,7 @@ function(tools, colorMap) {
(values[0] & 0xff) << 24 |
(values[1] & 0xff) << 16 |
(values[2] & 0xff) << 8 |
- (alpha || values[3] * 0xff & 0xff)
+ (alpha || min(1, max(0, values[3])) * 0xff & 0xff)
) >>> 0;
}
break;
View
5 test/color-spec.js
@@ -86,6 +86,11 @@ define([
expect(toRGBA('rgba(1,99,233,0)')).toBe('rgba(1,99,233,0)');
expect(toRGBA('rgba(1, 99, 233, 0)')).toBe('rgba(1,99,233,0)');
expect(toRGBA('rgba(1, 99, 233, 0)')).toBe('rgba(1,99,233,0)');
+ // Forces bounds of 0..1 for alpha:
+ expect(toRGBA('rgba(1,2,3,4444)')).toBe('rgba(1,2,3,1)');
+ expect(toRGBA('rgba(1,2,3,255)')).toBe('rgba(1,2,3,1)');
+ expect(toRGBA('rgba(1,2,3,-1)')).toBe('rgba(1,2,3,0)');
+ expect(toRGBA('rgba(1,2,3,1.101)')).toBe('rgba(1,2,3,1)');
});
it('Can handle hsl()', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.