Skip to content

Commit 885a1ed

Browse files
add not_component argument for ngx.escape_uri
1 parent 7cecbec commit 885a1ed

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

README.markdown

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5581,13 +5581,20 @@ This method was introduced in the `0.5.0rc30` release.
55815581
ngx.escape_uri
55825582
--------------
55835583

5584-
**syntax:** *newstr = ngx.escape_uri(str, not_component?)*
5584+
**syntax:** *newstr = ngx.escape_uri(str)*
55855585

55865586
**context:** *init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua**
55875587

55885588
Escape `str` as a URI component.
5589-
Since the `v0.10.16rc6` release, this function accepts an optional boolean `not_component` argument. When this argument is `true`, this function act like encodeURI. These characters bellow will not be escape.
5590-
a-zA-Z0-9-_.~!*'();:@&=+$,/?#
5589+
5590+
Since `v0.10.16rc6`, this function accepts an optional boolean `not_component` argument. When this argument is `true`, these characters bellow will not be escaped.
5591+
5592+
5593+
Alphabets: a-zA-Z
5594+
Digits: 0-9
5595+
Reserve characters: -_.~!*'();:@&=+$,/?#
5596+
5597+
55915598

55925599
[Back to TOC](#nginx-api-for-lua)
55935600

doc/HttpLuaModule.wiki

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4692,6 +4692,15 @@ This method was introduced in the <code>0.5.0rc30</code> release.
46924692
46934693
Escape <code>str</code> as a URI component.
46944694
4695+
Since `v0.10.16rc6`, this function accepts an optional boolean <code>not_component</code> argument. When this argument is <code>true</code>, these characters bellow will not be escaped.
4696+
4697+
<geshi lang="text">
4698+
Alphabets: a-zA-Z
4699+
Digits: 0-9
4700+
Reserve characters: -_.~!*'();:@&=+$,/?#
4701+
</geshi>
4702+
4703+
46954704
== ngx.unescape_uri ==
46964705
46974706
'''syntax:''' ''newstr = ngx.unescape_uri(str)''

src/ngx_http_lua_string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ ngx_http_lua_ffi_unescape_uri(const u_char *src, size_t len, u_char *dst)
433433

434434

435435
size_t
436-
ngx_http_lua_ffi_uri_escaped_length(const u_char *src, size_t len,
436+
ngx_http_lua_ffi_uri_escaped_length(const u_char *src, size_t len,
437437
int not_component)
438438
{
439439
int type = not_component ? NGX_ESCAPE_URI : NGX_ESCAPE_URI_COMPONENT;
@@ -442,7 +442,7 @@ ngx_http_lua_ffi_uri_escaped_length(const u_char *src, size_t len,
442442

443443

444444
void
445-
ngx_http_lua_ffi_escape_uri(const u_char *src, size_t len, u_char *dst,
445+
ngx_http_lua_ffi_escape_uri(const u_char *src, size_t len, u_char *dst,
446446
int not_component)
447447
{
448448
int type = not_component ? NGX_ESCAPE_URI : NGX_ESCAPE_URI_COMPONENT;

src/ngx_http_lua_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ ngx_http_lua_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
18921892
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
18931893

18941894
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1895-
0x50000051, /* 0101 0000 0000 0000 0000 0000 0010 0101 */
1895+
0x50000025, /* 0101 0000 0000 0000 0000 0000 0010 0101 */
18961896

18971897
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
18981898
0x78000000, /* 0111 1000 0000 0000 0000 0000 0000 0000 */

t/006-escape.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ GET /lua
207207
ngx.say(ngx.escape_uri("https://www.google.com", true))
208208
ngx.say(ngx.escape_uri("https://www.google.com/query?q=test", true))
209209
ngx.say(ngx.escape_uri("https://www.google.com/query?\r\nq=test", true))
210+
ngx.say(ngx.escape_uri("-_.~!*'();:@&=+$,/?#", true))
211+
ngx.say(ngx.escape_uri("<>[]{}\\\" ", true))
210212
}
211213
}
212214
--- request
@@ -215,5 +217,7 @@ GET /lua
215217
https://www.google.com
216218
https://www.google.com/query?q=test
217219
https://www.google.com/query?%0D%0Aq=test
220+
-_.~!*'();:@&=+$,/?#
221+
%3C%3E%5B%5D%7B%7D%5C%22%20
218222
--- no_error_log
219223
[error]

0 commit comments

Comments
 (0)