aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtiene <dalcol@etiene.net>2014-03-13 09:44:34 +0000
committerEtiene <dalcol@etiene.net>2014-03-13 09:44:34 +0000
commitb6aa0fceec7ae22d54985043a2d216e28ce941ac (patch)
treed401a86df7fdd0aa1405e70ab4f5fef33ff26012
parent5b00ea40b9196be62ab956cb264da14c6bccb6bf (diff)
downloadvalua-b6aa0fceec7ae22d54985043a2d216e28ce941ac.tar.gz
valua-b6aa0fceec7ae22d54985043a2d216e28ce941ac.tar.bz2
valua-b6aa0fceec7ae22d54985043a2d216e28ce941ac.zip
New email pattern match
-rw-r--r--valua-test.lua8
-rw-r--r--valua.lua2
2 files changed, 6 insertions, 4 deletions
diff --git a/valua-test.lua b/valua-test.lua
index 0291aaf..35dc247 100644
--- a/valua-test.lua
+++ b/valua-test.lua
@@ -7,7 +7,7 @@ local function check(val_test, test_value, expected, n)
if res == expected then
msg = msg.. "succeeded"
else
- msg = msg.. "FAILED"
+ msg = msg.. " \27[31m FAILED \27[0m"
end
msg = msg.." on '"..(tostring(test_value)).."'. Expected: "..tostring(expected)..", result: "..tostring(res)..". "
print(msg)
@@ -30,7 +30,9 @@ local test_values = {
'asd123',
5.7,
{},
- {3,46}
+ {3,46},
+ "<script>alert('boohoo@email.com XSS');</script>",
+ "test-123_maria.2@newdomain.wow.movie"
}
local tests = {
@@ -47,7 +49,7 @@ local tests = {
{v:new().number().max(1009),{7,false,6,true}},
{v:new().date(),{9,false,10,false,11,true,8,true}},
{v:new().date('us'),{8,false,9,true}},
- {v:new().email(),{13,false,12,true}},
+ {v:new().email(),{13,false,12,true,17,false,18,true}},
{v:new().in_list({"hey",42}),{12,false,6,true,2,true}},
{v:new().match("^%d+%p%d+%p%d%d%d%d$"),{1,false,8,true}},
{v:new().alnum(),{8,false,13,true}},
diff --git a/valua.lua b/valua.lua
index 8ffdccf..dad5a65 100644
--- a/valua.lua
+++ b/valua.lua
@@ -93,7 +93,7 @@ function valua._compare(value,another_value)
end
function valua._email(value)
- if not value:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w+") then
+ if not value:match("^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$") then
return false, "is not a valid email address"
end
return true