From 15817e78a162be95870e28df62091f2345202acb Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Thu, 31 May 2018 12:31:18 -0700 Subject: [PATCH] Fix case where lack of colour attribute results in null. (#1894) Fixes regression in #1893. Patch on change in #1831. Verify typeof colour variable before passing through Number(). Missing attributes return null, and Number(null) === 0, resulting in a red hues category color. --- core/toolbox.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/toolbox.js b/core/toolbox.js index a0e692a2d..359fec8bb 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -334,10 +334,14 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) { // (eg. `%{BKY_MATH_HUE}`). var colour = Blockly.utils.replaceMessageReferences( childIn.getAttribute('colour')); - if (/^#[0-9a-fA-F]{6}$/.test(colour)) { + if (colour === null || colour === '') { + // No attribute. No colour. + childOut.hexColour = ''; + } else if (/^#[0-9a-fA-F]{6}$/.test(colour)) { childOut.hexColour = colour; this.hasColours_ = true; - } else if (!isNaN(Number(colour))) { + } else if (typeof colour === 'number' + || (typeof colour === 'string' && !isNaN(Number(colour)))) { childOut.hexColour = Blockly.hueToRgb(Number(colour)); this.hasColours_ = true; } else {