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.
This commit is contained in:
Andrew n marshall
2018-05-31 12:31:18 -07:00
committed by GitHub
parent 5159de83cf
commit 15817e78a1

View File

@@ -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 {