From 37323aa70abc9aabe29c561d4d9f08807255b3e8 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 31 Jan 2008 16:29:10 +0000 Subject: Added function is_valid_filename() which for the moment just checks for valid path. Changed some other functions that called other functions (don't think they worked). git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@669 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/validator.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/validator.lua b/lib/validator.lua index 6f7fb65..a008397 100755 --- a/lib/validator.lua +++ b/lib/validator.lua @@ -35,6 +35,14 @@ validator.msg.err.OutOfRange = {} validator.msg.err.OutOfRange[lang.English] = "Value out of range!" validator.msg.err.OutOfRange[lang.German] = "Wert ausserhalb des Bereichs!" +validator.msg.err.FileInvalidPath = {} +validator.msg.err.FileInvalidPath[lang.English] = "Not a valid path!" +validator.msg.err.FileInvalidPath1 = {} +validator.msg.err.FileInvalidPath1[lang.English] = "You entered" +validator.msg.err.FileInvalidPath2 = {} +validator.msg.err.FileInvalidPath2[lang.English] = "You are restrected to" + + function is_string ( str ) if type(str) == "string" then return true, str, "Is a string." @@ -165,9 +173,9 @@ end -- and if it is within a given range. -- function is_integer_in_range(numstr, min, max) - return validator.is_integer(numstr) - and numstr >= min - and numstr <= max + return is_integer(numstr) + and tonumber(numstr) >= min + and tonumber(numstr) <= max end @@ -176,6 +184,14 @@ end -- and wheter it is between 1 .. 65535 -- function is_port(numstr) - return validator.is_integer_in_range(numstr, 1, 65535) + return is_integer_in_range(numstr, 1, 65535) end +function is_valid_filename ( path, restriction ) + if not (path) or ((restriction) and (string.find (path, "^" .. restriction ) == nil)) then + return nil, validator.msg.err.FileInvalidPath[lang.Current] .. "\n" .. + " * " .. validator.msg.err.FileInvalidPath1[lang.Current] ..":" .. string.format(path) .. "\n * ".. + validator.msg.err.FileInvalidPath2[lang.Current] .. ":" .. string.format(restriction) + end + return path +end -- cgit v1.2.3