@@ -18,14 +18,18 @@ local ngx_lua_ffi_escape_uri
18
18
local ngx_lua_ffi_unescape_uri
19
19
local ngx_lua_ffi_uri_escaped_length
20
20
21
+ local NGX_ESCAPE_URI = 0
22
+ local NGX_ESCAPE_URI_COMPONENT = 2
23
+ local NGX_ESCAPE_MAIL_AUTH = 6
24
+
21
25
22
26
if subsystem == " http" then
23
27
ffi .cdef [[
24
28
size_t ngx_http_lua_ffi_uri_escaped_length (const unsigned char * src ,
25
- size_t len );
29
+ size_t len , int type );
26
30
27
31
void ngx_http_lua_ffi_escape_uri (const unsigned char * src , size_t len ,
28
- unsigned char * dst );
32
+ unsigned char * dst , int type );
29
33
30
34
size_t ngx_http_lua_ffi_unescape_uri (const unsigned char * src ,
31
35
size_t len , unsigned char * dst );
@@ -38,10 +42,10 @@ if subsystem == "http" then
38
42
elseif subsystem == " stream" then
39
43
ffi .cdef [[
40
44
size_t ngx_stream_lua_ffi_uri_escaped_length (const unsigned char * src ,
41
- size_t len );
45
+ size_t len , int type );
42
46
43
47
void ngx_stream_lua_ffi_escape_uri (const unsigned char * src , size_t len ,
44
- unsigned char * dst );
48
+ unsigned char * dst , int type );
45
49
46
50
size_t ngx_stream_lua_ffi_unescape_uri (const unsigned char * src ,
47
51
size_t len , unsigned char * dst );
@@ -53,22 +57,38 @@ elseif subsystem == "stream" then
53
57
end
54
58
55
59
56
- ngx .escape_uri = function (s )
60
+ ngx .escape_uri = function (s , esc_type )
57
61
if type (s ) ~= ' string' then
58
62
if not s then
59
63
s = ' '
64
+
60
65
else
61
66
s = tostring (s )
62
67
end
63
68
end
69
+
70
+ if esc_type == nil then
71
+ esc_type = NGX_ESCAPE_URI_COMPONENT
72
+
73
+ else
74
+ if type (esc_type ) ~= ' number' then
75
+ error (" \" type\" is not number" , 3 )
76
+ end
77
+
78
+ if esc_type < NGX_ESCAPE_URI or esc_type > NGX_ESCAPE_MAIL_AUTH then
79
+ error (" \" type\" " .. esc_type .. " out of range" , 3 )
80
+ end
81
+ end
82
+
64
83
local slen = # s
65
- local dlen = ngx_lua_ffi_uri_escaped_length (s , slen )
84
+ local dlen = ngx_lua_ffi_uri_escaped_length (s , slen , esc_type )
85
+
66
86
-- print("dlen: ", tonumber(dlen))
67
87
if dlen == slen then
68
88
return s
69
89
end
70
90
local dst = get_string_buf (dlen )
71
- ngx_lua_ffi_escape_uri (s , slen , dst )
91
+ ngx_lua_ffi_escape_uri (s , slen , dst , esc_type )
72
92
return ffi_string (dst , dlen )
73
93
end
74
94
0 commit comments