From c1ee15e1a890c11f2a7ad9691c689fdb60f71253 Mon Sep 17 00:00:00 2001 From: Alice Boxhall Date: Wed, 28 May 2014 07:41:47 -0700 Subject: [PATCH] Correctly parse alpha in rgba colors --- src/js/AccessibilityUtils.js | 4 ++-- test/js/utils-test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/js/AccessibilityUtils.js b/src/js/AccessibilityUtils.js index e0ce41f6..b277ee94 100644 --- a/src/js/AccessibilityUtils.js +++ b/src/js/AccessibilityUtils.js @@ -507,13 +507,13 @@ axs.utils.parseColor = function(colorString) { return new axs.utils.Color(r, g, b, a); } - var rgbaRegex = /^rgba\((\d+), (\d+), (\d+), (\d+(\.\d+)?)\)/; + var rgbaRegex = /^rgba\((\d+), (\d+), (\d+), (\d*(\.\d+)?)\)/; match = colorString.match(rgbaRegex); if (match) { - var a = parseInt(match[4], 10); var r = parseInt(match[1], 10); var g = parseInt(match[2], 10); var b = parseInt(match[3] ,10); + var a = parseFloat(match[4]); return new axs.utils.Color(r, g, b, a); } diff --git a/test/js/utils-test.js b/test/js/utils-test.js index 0c4e444d..80e586c1 100644 --- a/test/js/utils-test.js +++ b/test/js/utils-test.js @@ -148,3 +148,13 @@ test("nth-of-type does not refer to a selector but a tagName", function() { equal(lastLi, document.querySelector(selector), 'selector "' + selector + '" does not match element'); }); + +module("parseColor"); +test("parses alpha values correctly", function() { + var colorString = 'rgba(255, 255, 255, .47)'; + var color = axs.utils.parseColor(colorString); + equal(color.red, 255); + equal(color.blue, 255); + equal(color.green, 255); + equal(color.alpha, .47); +});