From 8d0f50c2de48acd99d6cc596e6b08feac7a04360 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 26 Oct 2010 14:57:09 -0700 Subject: [PATCH] Tighter hex parsing, a-fA-F\d only --- lib/canvas.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/canvas.js b/lib/canvas.js index 44d9f4d..927e95c 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -119,7 +119,7 @@ var parseColor = exports.parseColor = function(str){ ]; // #RRGGBB } else if ('#' == str.charAt(0) && str.length > 4) { - var captures = /#(\w{2})(\w{2})(\w{2})/.exec(str); + var captures = /#([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})/.exec(str); if (!captures) return; return cache[str] = [ parseInt(captures[1], 16) @@ -129,7 +129,7 @@ var parseColor = exports.parseColor = function(str){ ]; // #RGB } else if ('#' == str.charAt(0)) { - var captures = /#(\w)(\w)(\w)/.exec(str); + var captures = /#([a-fA-F\d])([a-fA-F\d])([a-fA-F\d])/.exec(str); if (!captures) return; return cache[str] = [ parseInt(captures[1] + captures[1], 16)