Browse Source

Tighter hex parsing, a-fA-F\d only

v1.x
Tj Holowaychuk 14 years ago
parent
commit
8d0f50c2de
  1. 4
      lib/canvas.js

4
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)

Loading…
Cancel
Save