From ca3e18f0310127be027e0e12d52128240cc76f6d Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Wed, 14 Nov 2018 11:24:27 -0800 Subject: [PATCH] Fixed a NPE in decoding the RGB values (#62) * Fixed a NPE in decoding the RGB values * Fix the formatting --- index.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index cf3c830..0e1cfc2 100644 --- a/index.html +++ b/index.html @@ -57,13 +57,17 @@ } function rgb_to_array(str) { - m = str.match(/^#([0-9a-f]{6})$/i)[1]; + matches = str.match(/^#([0-9a-f]{6})$/i) + if (!matches) { + return [0,0,0] + } + m = matches[1]; if(m) { return [ parseInt(m.substr(0,2),16), - parseInt(m.substr(2,2),16), - parseInt(m.substr(4,2),16) - ]; + parseInt(m.substr(2,2),16), + parseInt(m.substr(4,2),16) + ]; } }