Skip to content

Commit 6c7c481

Browse files
add not_component argument for ngx.escape_uri
1 parent 7904459 commit 6c7c481

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
@@ -5567,13 +5567,20 @@ This method was introduced in the `0.5.0rc30` release.
55675567
ngx.escape_uri
55685568
--------------
55695569

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

55725572
**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**
55735573

55745574
Escape `str` as a URI component.
5575-
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.
5576-
a-zA-Z0-9-_.~!*'();:@&=+$,/?#
5575+
5576+
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.
5577+
5578+
5579+
Alphabets: a-zA-Z
5580+
Digits: 0-9
5581+
Reserve characters: -_.~!*'();:@&=+$,/?#
5582+
5583+
55775584

55785585
[Back to TOC](#nginx-api-for-lua)
55795586

doc/HttpLuaModule.wiki

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,6 +4678,15 @@ This method was introduced in the <code>0.5.0rc30</code> release.
46784678
46794679
Escape <code>str</code> as a URI component.
46804680
4681+
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.
4682+
4683+
<geshi lang="text">
4684+
Alphabets: a-zA-Z
4685+
Digits: 0-9
4686+
Reserve characters: -_.~!*'();:@&=+$,/?#
4687+
</geshi>
4688+
4689+
46814690
== ngx.unescape_uri ==
46824691
46834692
'''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)