diff --git a/minetest/colorspec.lua b/minetest/colorspec.lua index 166015c..ce54ef8 100644 --- a/minetest/colorspec.lua +++ b/minetest/colorspec.lua @@ -203,7 +203,7 @@ function colorspec.from_string(string) if not number then local name, alpha_text = string:match("^([a-z]+)" .. hex .. "$") if name then - if alpha_text:len() ~= 2 then + if alpha_text:len() > 2 then return end number = named_colors[name] @@ -211,6 +211,9 @@ function colorspec.from_string(string) return end alpha = tonumber(alpha_text, 0x10) + if alpha_text:len() == 1 then + alpha = alpha * 0x11 + end end end if number then diff --git a/test.lua b/test.lua index ae3f12c..ddd2832 100644 --- a/test.lua +++ b/test.lua @@ -389,6 +389,7 @@ local spec = colorspec.from_number_rgba(0xDDCCBBAA) assertdump(table.equals(spec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD}), spec) test_from_string("aliceblue", 0xf0f8ffff) test_from_string("aliceblue#42", 0xf0f8ff42) +test_from_string("aliceblue#3", 0xf0f8ff33) test_from_string("#333", 0x333333FF) test_from_string("#694269", 0x694269FF) test_from_string("#11223344", 0x11223344)