From 952674a161a30f09743f7c080cc6160dbd141d39 Mon Sep 17 00:00:00 2001 From: Erlend <49862976+Erb3@users.noreply.github.com> Date: Wed, 17 May 2023 20:20:53 +0200 Subject: [PATCH] Improve argument validation in colors.fromBlit --- .../data/computercraft/lua/rom/apis/colors.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua index 388b087e1..f582ff10e 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/colors.lua @@ -372,7 +372,7 @@ end --- Converts the given paint/blit hex character (0-9a-f) to a color. -- --- This is equivalent to converting the hex character to decimal and then 2 ^ decimal +-- This is equivalent to converting the hex character to a number and then 2 ^ decimal -- -- @tparam string hex The paint/blit hex character to convert -- @treturn number The color @@ -387,9 +387,9 @@ end function fromBlit(hex) expect(1, hex, "string") - if hex:find("[^0-9a-f]") or hex == "" then - return - end + if #hex ~= 1 then return nil end + local value = tonumber(hex, 16) + if not value then return nil end - return math.floor(2 ^ tonumber(hex, 16)) + return 2 ^ value end