瀏覽代碼

Fix rare Cannot read property '1' of null error

Gaël Métais 9 年之前
父節點
當前提交
4f9589fb6b
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      lib/tools/colorDiff.js

+ 4 - 2
lib/tools/colorDiff.js

@@ -46,7 +46,9 @@ var colorDiff = function() {
         var deduplicatedColors = {};
 
         parsedOffenders.forEach(function(color) {
-            deduplicatedColors[color] = color;
+            if (color !== null) {
+                deduplicatedColors[color] = color;
+            }
         });
 
         return Object.keys(deduplicatedColors).map(this.parseColor);
@@ -54,7 +56,7 @@ var colorDiff = function() {
 
     this.parseOffender = function(offender) {
         var regexResult = /^(.*) \(\d+ times\)$/.exec(offender);
-        return regexResult[1];
+        return regexResult ? regexResult[1] : null;
     };
 
     this.parseColor = function(color) {