From 0c18b4952da10feadc5826417014aaeeeb929561 Mon Sep 17 00:00:00 2001 From: jokebookservice1 Date: Wed, 10 Oct 2018 19:45:36 +0100 Subject: [PATCH] refactor: use better whitespace-test for backdrops too --- src/blocks/scratch3_looks.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index dbf4be7a3..6addc629a 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -403,8 +403,10 @@ class Scratch3LooksBlocks { if (selectedIndex === stage.currentCostume) selectedIndex += 1; stage.setCostume(selectedIndex); } - } else if (!isNaN(requestedBackdrop) && - (typeof requestedBackdrop !== 'string' || /\d/g.test(requestedBackdrop))) { + // Try to cast the string to a number (and treat it as a costume index) + // Pure whitespace should not be treated as a number (JS casts this to 0) + // Note: isNaN will cast the string to a number before checking if it's NaN + } else if (!(isNaN(requestedBackdrop) || Cast.isWhiteSpace(requestedBackdrop))) { stage.setCostume(optZeroIndex ? Number(requestedBackdrop) : Number(requestedBackdrop) - 1); } }