Skip to content

Commit 89ebde2

Browse files
committed
Release 2.5.
1 parent af5f1b1 commit 89ebde2

File tree

7 files changed

+64
-29
lines changed

7 files changed

+64
-29
lines changed

CHANGES

Lines changed: 0 additions & 26 deletions
This file was deleted.

Changes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Change Log
2+
3+
All notable changes to `lua-resty-validation` will be documented in this file.
4+
5+
## [2.5] - 2016-09-29
6+
### Added
7+
- Support for the official OpenResty package manager (opm).
8+
9+
### Changed
10+
- Changed the change log format to keep-a-changelog.
11+
12+
## [2.4] - 2016-09-16
13+
### Added
14+
- Added support for custom (inline) validators.
15+
- Added resty.validation.injection extension (uses libinjection).
16+
17+
## [2.3] - 2016-03-22
18+
### Added
19+
- Added resty.validation.utf8 extension (uses utf8rewind).
20+
21+
## [2.2] - 2015-11-27
22+
### Fixed
23+
- There was a typo in a code that leaked a global variable in fields:__call method.
24+
25+
## [2.1] - 2015-10-10
26+
### Fixed
27+
- Fixed leaking global new function.
28+
29+
## [2.1] - 2015-10-10
30+
### Changes
31+
- Total rewrite.
32+
33+
## [1.0] - 2014-08-28
34+
### Added
35+
- LuaRocks support via MoonRocks.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016, Aapo Talvensaari
1+
Copyright (c) 2014 - 2016, Aapo Talvensaari
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,14 @@ It will monkey patch the adapters that it will provide in `resty.validation`, an
344344
* `crc32short`
345345
* `crc32long`
346346
* `crc32`
347+
* `md5`
347348

348349
(there is both factory and argument-less version of these)
349350

350-
There is also regex matcher in ngx that uses `ngx.re.match`:
351+
There is also regex matcher in ngx extension that uses `ngx.re.match`, and parameterized `md5`:
351352

352353
* `regex(regex[, options])`
354+
* `md5([bin])`
353355

354356
##### Example
355357

@@ -515,6 +517,11 @@ local valid, ts = validation.xss("test <script>alert('XSS');</script>")
515517
I'm not going here for details for all the different validators and filters there is because they all follow the
516518
same logic, but I will show some general ways how this works.
517519

520+
### validation._VERSION
521+
522+
This field contains a version of the validation library, e.g. it's value can be `"2.5"` for
523+
the version 2.5 of this library.
524+
518525
### boolean, value/error validation...
519526

520527
That `...` means the validation chain. This is used to define a single validator chain. There is no limit to

dist.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = lua-resty-validation
2+
abstract = Validation Library (Input Validation and Filtering) for Lua and OpenResty
3+
author = Aapo Talvensaari (@bungle)
4+
is_original = yes
5+
license = 2bsd
6+
repo_link = https://github.com/bungle/lua-resty-validation

lib/resty/validation.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local _VERSION = "2.5"
2+
13
local setmetatable = setmetatable
24
local getmetatable = getmetatable
35
local rawget = rawget
@@ -660,7 +662,7 @@ local function check(validator, value, valid, v)
660662
return true, v
661663
end
662664
local function validation(func, parent_f, parent, method)
663-
return setmetatable({ new = new, group = group, fields = setmetatable({}, fields), nothing = nothing, stop = stop, validators = validators }, {
665+
return setmetatable({ new = new, group = group, fields = setmetatable({}, fields), nothing = nothing, stop = stop, validators = validators, _VERSION = _VERSION }, {
664666
__index = function(self, index)
665667
return validation(function(...)
666668
local valid, value = check(index, select(1, ...), func(...))

lib/resty/validation/ngx.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local base64enc = ngx.encode_base64
66
local base64dec = ngx.decode_base64
77
local crc32short = ngx.crc32_short
88
local crc32long = ngx.crc32_long
9+
local md5 = ngx.md5
10+
local md5bin = ngx.md5bin
911
local match = ngx.re.match
1012
local validators = validation.validators
1113
local factory = getmetatable(validators)
@@ -51,6 +53,13 @@ function factory.crc32()
5153
return true, crc32long(value)
5254
end
5355
end
56+
function factory.md5(bin)
57+
return function(value)
58+
local digest = bin and md5bin(value) or md5(value)
59+
return true, digest
60+
end
61+
end
62+
5463
function factory.regex(regex, options)
5564
return function(value)
5665
return (match(value, regex, options)) ~= nil
@@ -63,6 +72,7 @@ validators.base64dec = factory.base64dec()
6372
validators.crc32short = factory.crc32short()
6473
validators.crc32long = factory.crc32long()
6574
validators.crc32 = factory.crc32()
75+
validators.md5 = factory.md5()
6676
return {
6777
escapeuri = validators.escapeuri,
6878
unescapeuri = validators.unescapeuri,
@@ -71,5 +81,6 @@ return {
7181
crc32short = validators.crc32short,
7282
crc32long = validators.crc32long,
7383
crc32 = validators.crc32,
84+
md5 = validators.md5,
7485
regex = factory.regex
7586
}

0 commit comments

Comments
 (0)