mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-27 01:46:03 +00:00
api: escape all magic chars in sanitize pattern
This commit is contained in:
+2
-6
@@ -168,20 +168,16 @@ local sanitize_cache = {}
|
||||
function pfUI.api.SanitizePattern(pattern, dbg)
|
||||
if not sanitize_cache[pattern] then
|
||||
local ret = pattern
|
||||
-- escape brackets
|
||||
ret = gsub(ret, "%((.+)%)", "%%(%1%%)")
|
||||
-- escape magic characters
|
||||
ret = gsub(ret, "([%+%-%*%(%)%?%[%]%^])", "%%%1")
|
||||
-- remove capture indexes
|
||||
ret = gsub(ret, "%d%$","")
|
||||
|
||||
-- catch all characters
|
||||
ret = gsub(ret, "(%%%a)","%(%1+%)")
|
||||
|
||||
-- convert all %s to .+
|
||||
ret = gsub(ret, "%%s%+",".+")
|
||||
|
||||
-- set priority to numbers over strings
|
||||
ret = gsub(ret, "%(.%+%)%(%%d%+%)","%(.-%)%(%%d%+%)")
|
||||
|
||||
-- cache it
|
||||
sanitize_cache[pattern] = ret
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user