From fcb136394cc85b60f17fcda43da3551e2f47c01f Mon Sep 17 00:00:00 2001 From: Krathe Date: Sun, 10 May 2026 16:37:25 +0100 Subject: [PATCH] (Pet Frames) Fix Lua error on pet name update in instanced content GetUnitName can return a secret string value in delves and encounters. The previous code called #name and name:sub() on the result, which throws a Lua error the moment any string operation is attempted on a secret value. Routes truncation through DF:UTF8Len / DF:UTF8Sub, which both guard on issecretvalue internally and return safe defaults (0 / "") when the input is secret. The truncation branch no-ops, SetText still receives the secret string, and FontStrings render it correctly without taint. Supersedes PR #67 which skipped SetText entirely on secret values, leaving the pet name text stale rather than updating it. --- Frames/Pets.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Frames/Pets.lua b/Frames/Pets.lua index fa050d0f..445392f9 100644 --- a/Frames/Pets.lua +++ b/Frames/Pets.lua @@ -536,11 +536,15 @@ function DF:UpdatePetName(frame) local name = GetUnitName(frame.unit, true) if name then - -- Truncate long names + -- Truncate long names. Use secret-value-safe UTF-8 helpers — GetUnitName + -- can return a secret string in instanced content (delves, encounters). + -- DF:UTF8Len returns 0 for secret values so the truncation branch + -- no-ops, and SetText receives the secret string directly (FontStrings + -- accept secret values; only Lua string ops on them cause errors). local db = DF:GetFrameDB(frame) local maxLen = db.petNameMaxLength or 12 - if #name > maxLen then - name = name:sub(1, maxLen) .. "..." + if maxLen > 0 and DF:UTF8Len(name) > maxLen then + name = DF:UTF8Sub(name, 1, maxLen) .. "..." end frame.nameText:SetText(name) end