diff options
author | garret <garret@airmail.cc> | 2023-02-16 10:17:54 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-02-16 10:17:54 +0000 |
commit | 4749fc16932b6076f0a5c01180db9705d2582608 (patch) | |
tree | 5f6dd53f1a26c66c039c1acc9dc293e9b9c4d69d /make-feed.lua | |
parent | 3c1896e911017808a4266214ed08242db2eb2304 (diff) | |
download | depctrl-feedmaker-4749fc16932b6076f0a5c01180db9705d2582608.tar.gz depctrl-feedmaker-4749fc16932b6076f0a5c01180db9705d2582608.tar.bz2 depctrl-feedmaker-4749fc16932b6076f0a5c01180db9705d2582608.zip |
add proper namespace validation
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-x | make-feed.lua | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/make-feed.lua b/make-feed.lua index 5a35acd..be4cde7 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -15,7 +15,7 @@ local args = parser:parse() local config = loadfile(args.config)() -local function valid_namespace(name) +local function valid_namespace(str) --[[ #### Rules for a valid namespace: #### 1. contains _at least_ one dot @@ -30,8 +30,30 @@ __Examples__: * a-mo.LineCollection ]] - return name:match("^[^.][%a%d._-]*%.[%a%d._-]*[^.]$") ~= nil - -- not 100% sure this works. it matches the examples, but idk if it matches invalid ones as well +-- written by chatgpt lol + + -- Check if the string contains at least one dot + if not string.find(str, '%.') then + return false + end + + -- Check if the string starts or ends with a dot + if string.sub(str, 1, 1) == '.' or string.sub(str, -1) == '.' then + return false + end + + -- Check if the string contains a series of two or more dots + if string.find(str, '%.%.') then + return false + end + + -- Check if the string contains invalid characters + if string.find(str, '[^%w%.%-_]') then + return false + end + + -- If all checks pass, the string is valid + return true end local function clean_path(path, file) |