Skip to content

Commit 3643b60

Browse files
committed
bugfix: call the right pcre method.
1 parent 48f4ec6 commit 3643b60

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

resty/jsonschema.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,28 +883,28 @@ generate_validator = function(ctx, schema)
883883

884884
if schema.format == "email" then
885885
local reg = [[^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$]]
886-
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:libfunc('custom.match_pattern'), ctx:param(1), ctx:param(1), reg))
886+
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:param(1), ctx:libfunc('custom.match_pattern'), ctx:param(1), reg))
887887
ctx:stmt(sformat(' return false, "expect valid email address but got: " .. %s', ctx:param(1)))
888888
ctx:stmt( 'end')
889889
end
890890

891891
if schema.format == "ipv4" then
892892
local reg = [[^(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))$]]
893-
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:libfunc('custom.match_pattern'), ctx:param(1), ctx:param(1), reg))
893+
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:param(1), ctx:libfunc('custom.match_pattern'), ctx:param(1), reg))
894894
ctx:stmt(sformat(' return false, "expect valid ipv4 address but got: " .. %s', ctx:param(1)))
895895
ctx:stmt( 'end')
896896
end
897897

898898
if schema.format == "ipv6" then
899899
local reg = [[^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$]]
900-
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:libfunc('custom.match_pattern'), ctx:param(1), ctx:param(1), reg))
900+
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:param(1), ctx:libfunc('custom.match_pattern'), ctx:param(1), reg))
901901
ctx:stmt(sformat(' return false, "expect valid ipv6 address but got: " .. %s', ctx:param(1)))
902902
ctx:stmt( 'end')
903903
end
904904

905905
if schema.format == "hostname" then
906906
local reg = [[^[a-zA-Z0-9\-\.]+$]]
907-
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:libfunc('custom.match_pattern'), ctx:param(1), ctx:param(1), reg))
907+
ctx:stmt(sformat('if type(%s) == "string" and not %s(%s, [[%s]]) then', ctx:param(1), ctx:libfunc('custom.match_pattern'), ctx:param(1), reg))
908908
ctx:stmt(sformat(' return false, "expect valid ipv4 address but got: " .. %s', ctx:param(1)))
909909
ctx:stmt( 'end')
910910
end

t/draft4.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ for _, descriptor in ipairs(supported) do
115115
if skipped ~= true then
116116
local validator = jsonschema.generate_validator(suite.schema, {
117117
name = suite.description,
118+
match_pattern = ngx.re.find,
118119
})
119120
for _, case in ipairs(suite.tests) do
120121
if skipped[case.description] then

t/draft6.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ for _, descriptor in ipairs(supported) do
120120
if skipped ~= true then
121121
local validator = jsonschema.generate_validator(suite.schema, {
122122
name = suite.description,
123+
match_pattern = ngx.re.find,
123124
})
124125
for _, case in ipairs(suite.tests) do
125126
if skipped[case.description] then

t/draft7.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ for _, descriptor in ipairs(supported) do
123123
if skipped ~= true then
124124
local validator = jsonschema.generate_validator(suite.schema, {
125125
name = suite.description,
126+
match_pattern = ngx.re.find,
126127
})
127128
for _, case in ipairs(suite.tests) do
128129
if skipped[case.description] then

0 commit comments

Comments
 (0)