From 1189968dab83181d328c24a19968d11d7bc8e50a Mon Sep 17 00:00:00 2001 From: NighthawkSLO Date: Tue, 3 Sep 2024 17:32:10 +0200 Subject: [PATCH 1/2] Fix percent progress validation and parsing --- WeakAuras/Prototypes.lua | 4 ++-- WeakAuras/RegionTypes/RegionPrototype.lua | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index f046c3eae8..c66ae0647a 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -984,8 +984,8 @@ end ---@return boolean result function WeakAuras.ValidateNumericOrPercent(info, val) if val ~= nil and val ~= "" then - local percent = string.match(val, "(%d+)%%") - local number = percent and tonumber(percent) or tonumber(val) + local percent, count = val:gsub("%%", " ", 1) + local number = count == 1 and tonumber(percent) or tonumber(val) if(not number or number >= 2^31) then return false; end diff --git a/WeakAuras/RegionTypes/RegionPrototype.lua b/WeakAuras/RegionTypes/RegionPrototype.lua index 13bd54af7e..6ba065c83e 100644 --- a/WeakAuras/RegionTypes/RegionPrototype.lua +++ b/WeakAuras/RegionTypes/RegionPrototype.lua @@ -348,8 +348,8 @@ local function SetProgressSource(self, progressSource) end local function SetAdjustedMin(self, adjustedMin) - local percent = string.match(adjustedMin, "(%d+)%%") - if percent then + local percent, count = adjustedMin:gsub("%%", " ", 1) + if count == 1 then self.adjustedMinRelPercent = tonumber(percent) / 100 self.adjustedMin = nil else @@ -360,8 +360,8 @@ local function SetAdjustedMin(self, adjustedMin) end local function SetAdjustedMax(self, adjustedMax) - local percent = string.match(adjustedMax, "(%d+)%%") - if percent then + local percent, count = adjustedMax:gsub("%%", " ", 1) + if count == 1 then self.adjustedMaxRelPercent = tonumber(percent) / 100 else self.adjustedMax = tonumber(adjustedMax) From c2e9323110ab390f40bcc780963099f34f41e500 Mon Sep 17 00:00:00 2001 From: NighthawkSLO Date: Tue, 3 Sep 2024 18:17:55 +0200 Subject: [PATCH 2/2] Fix another edge case for percent progress --- WeakAuras/Prototypes.lua | 4 ++-- WeakAuras/RegionTypes/RegionPrototype.lua | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index c66ae0647a..1fbb387766 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -984,8 +984,8 @@ end ---@return boolean result function WeakAuras.ValidateNumericOrPercent(info, val) if val ~= nil and val ~= "" then - local percent, count = val:gsub("%%", " ", 1) - local number = count == 1 and tonumber(percent) or tonumber(val) + local index = val:find("%% *$") + local number = index and tonumber(val:sub(1, index-1)) or tonumber(val) if(not number or number >= 2^31) then return false; end diff --git a/WeakAuras/RegionTypes/RegionPrototype.lua b/WeakAuras/RegionTypes/RegionPrototype.lua index 6ba065c83e..856cb4c3b8 100644 --- a/WeakAuras/RegionTypes/RegionPrototype.lua +++ b/WeakAuras/RegionTypes/RegionPrototype.lua @@ -348,8 +348,9 @@ local function SetProgressSource(self, progressSource) end local function SetAdjustedMin(self, adjustedMin) - local percent, count = adjustedMin:gsub("%%", " ", 1) - if count == 1 then + local index = adjustedMin:find("%% *$") + if index then + local percent = adjustedMin:sub(1, index-1) self.adjustedMinRelPercent = tonumber(percent) / 100 self.adjustedMin = nil else @@ -360,8 +361,9 @@ local function SetAdjustedMin(self, adjustedMin) end local function SetAdjustedMax(self, adjustedMax) - local percent, count = adjustedMax:gsub("%%", " ", 1) - if count == 1 then + local index = adjustedMax:find("%% *$") + if index then + local percent = adjustedMax:sub(1, index-1) self.adjustedMaxRelPercent = tonumber(percent) / 100 else self.adjustedMax = tonumber(adjustedMax)