From 3cf80c9272d1942587ce671c95236cca5c2c2cb7 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 28 Sep 2024 11:10:44 +0200 Subject: [PATCH] skinlist: Allow textures containing '-' characters Fixes issue #110 Thanks to Bastrabun for the code suggestion --- skinlist.lua | 2 +- textures/readme.txt | 1 + unittest.lua | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/skinlist.lua b/skinlist.lua index a588715..66045ed 100644 --- a/skinlist.lua +++ b/skinlist.lua @@ -6,7 +6,7 @@ local dbgprint = false and print or function() end function skins.register_skin(path, filename) -- See "textures/readme.txt" for allowed formats - local prefix, sep, identifier, extension = filename:match("^(%a+)([_.])([%w_.]+)%.(%a+)$") + local prefix, sep, identifier, extension = filename:match("^(%a+)([_.])([%w_.-]+)%.(%a+)$") --[[ prefix: "character" or "player" sep: "." (new) or "_" (legacy) diff --git a/textures/readme.txt b/textures/readme.txt index 3891dc9..73885f1 100644 --- a/textures/readme.txt +++ b/textures/readme.txt @@ -6,6 +6,7 @@ List of accepted texture names Public skin available for all users: character.[number or name].png + ^ The allowed characters in "[number or name]" are "[A-z0-9_.-]+". One or multiple private skins for player "[nick]": player.[nick].png diff --git a/unittest.lua b/unittest.lua index 7b745bc..bf476d2 100644 --- a/unittest.lua +++ b/unittest.lua @@ -9,12 +9,14 @@ local function run_unittest() -- ----- -- `.`: Simple register + retrieve operations - skins.register_skin(PATH, "player.DotSep.png") - skins.register_skin(PATH, "player._DotSep_666_.1.png") + assert(skins.register_skin(PATH, "player.DotSep.png")) + assert(skins.register_skin(PATH, "player._DotSep_666_.1.png")) + assert(skins.register_skin(PATH, "character._DotSep_With-Dash-.png")) assert(get_skin("player.DotSep")) assert(get_skin("player._DotSep_666_.1")) assert(get_skin("player.DotSep.1") == nil) + assert(get_skin("character._DotSep_With-Dash-")) -- ----- -- Ambiguous skin names (filenames without extension). Register + retrieve @@ -42,7 +44,6 @@ local function run_unittest() assert(get_skin("player_Com_Pat_42") == "player._Com_Pat_42") assert(get_skin("player_Com_Pat_42_1") == "player._Com_Pat_42.1") - error("Unittest passed! Please disable them now.") end