aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-24 15:51:06 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-24 15:51:16 -0700
commit0c07968e0716745f7b510a76e94ccf0910e4c4e7 (patch)
treeea924c3a7d8f8262bb380563b832fd3c2c5061e0
parent5758626bf7ac1789a2ef871b7683b23084c3dbb7 (diff)
Added error checking for bad paths.
-rw-r--r--nomsu.lua11
-rwxr-xr-xnomsu.moon8
2 files changed, 17 insertions, 2 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 07cd17f..10a3b66 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -88,7 +88,16 @@ all_files = function(path)
return iterate_single, path
end
path = path:gsub("\\", "\\\\"):gsub("`", ""):gsub('"', '\\"'):gsub("$", "")
- return io.popen('find -L "' .. path .. '" -type f -name "*.nom"'):lines()
+ return coroutine.wrap(function()
+ local f = io.popen('find -L "' .. path .. '" -type f -name "*.nom"')
+ for line in f:lines() do
+ coroutine.yield(line)
+ end
+ local success = f:close()
+ if not (success) then
+ return error("Invalid file path: " .. tostring(path))
+ end
+ end)
end
local line_counter = re.compile([[ lines <- {| line (%nl line)* |}
line <- {} (!%nl .)*
diff --git a/nomsu.moon b/nomsu.moon
index f7fc601..50a95d9 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -77,7 +77,13 @@ all_files = (path)->
return iterate_single, path
-- TODO: improve sanitization
path = path\gsub("\\","\\\\")\gsub("`","")\gsub('"','\\"')\gsub("$","")
- return io.popen('find -L "'..path..'" -type f -name "*.nom"')\lines!
+ return coroutine.wrap ->
+ f = io.popen('find -L "'..path..'" -type f -name "*.nom"')
+ for line in f\lines!
+ coroutine.yield(line)
+ success = f\close!
+ unless success
+ error("Invalid file path: "..tostring(path))
line_counter = re.compile([[
lines <- {| line (%nl line)* |}