Module:T-Campaign: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 187: Line 187:
         local finalTitle = rawTitle
         local finalTitle = rawTitle
          
          
         -- Step 2: Inspect the raw title's type and content
         -- Step 2: Launder the string to work around suspected Scribunto bug
         local rawType = type(rawTitle)
         local function launderString(inputStr)
        ErrorHandling.addStatus(context, 'campaignBanner', 'Inspecting raw title', 'Type: ' .. rawType)
            if type(inputStr) ~= 'string' then return tostring(inputStr) end
            local newStr = ""
            for i = 1, #inputStr do
                newStr = newStr .. string.char(string.byte(inputStr, i))
            end
            return newStr
        end


         if rawType == 'string' then
         local cleanTitle = launderString(rawTitle)
            -- It claims to be a string, let's inspect its byte content.
       
            local len = #rawTitle
        ErrorHandling.addStatus(context, 'campaignBanner', 'Laundered String', 'Original Type: ' .. type(rawTitle) .. ', Cleaned Value: "' .. cleanTitle .. '"')
            local bytes = ""
            if len > 0 then
                for i = 1, len do
                    bytes = bytes .. string.byte(rawTitle, i) .. " "
                end
            else
                bytes = "EMPTY STRING"
            end
            ErrorHandling.addStatus(context, 'campaignBanner', 'Inspecting string content', 'Length: ' .. len .. ', Bytes: ' .. bytes)
           
            -- Check for null characters specifically
            if rawTitle:find('\0') then
                ErrorHandling.addStatus(context, 'campaignBanner', 'NULL CHARACTER DETECTED', 'The string contains a null terminator, which is likely causing the issue.')
                -- Attempt to clean it
                finalTitle = rawTitle:gsub('\0', '')
                ErrorHandling.addStatus(context, 'campaignBanner', 'Cleaned string', 'New value: "' .. finalTitle .. '"')
            end


         elseif rawType == 'table' then
         -- If it's a table, we need to serialize it to see what's inside.
        if type(rawTitle) == 'table' then
             -- If it's a table, we need to serialize it to see what's inside.
             -- If it's a table, we need to serialize it to see what's inside.
             -- This is a simple serializer for demonstration.
             -- This is a simple serializer for demonstration.
Line 227: Line 217:
             -- Attempt to extract a string value. Let's assume the first value is what we want.
             -- Attempt to extract a string value. Let's assume the first value is what we want.
             if rawTitle[1] then
             if rawTitle[1] then
                 finalTitle = tostring(rawTitle[1])
                 cleanTitle = launderString(tostring(rawTitle[1]))
                 ErrorHandling.addStatus(context, 'campaignBanner', 'Extracted value from table', 'Using value at index 1: "' .. finalTitle .. '"')
                 ErrorHandling.addStatus(context, 'campaignBanner', 'Extracted value from table', 'Using value at index 1: "' .. cleanTitle .. '"')
             else
             else
                 -- Fallback if we can't find a value at index 1
                 -- Fallback if we can't find a value at index 1
                 finalTitle = tostring(rawTitle)
                 cleanTitle = launderString(tostring(rawTitle))
             end
             end
        elseif rawType ~= 'string' then
            -- Handle other non-string, non-table types
            finalTitle = tostring(rawTitle)
            ErrorHandling.addStatus(context, 'campaignBanner', 'Raw title is not a string or table', 'Using tostring() conversion: "' .. finalTitle .. '"')
         end
         end


         -- Step 3: Use the processed title for the placeholder
         -- Step 3: Use the processed title for the placeholder
         local placeholderValues = {
         local placeholderValues = {
             CAMPAIGN_NAME = finalTitle
             CAMPAIGN_NAME = cleanTitle
         }
         }