Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ struct ngx_http_lua_main_conf_s {
of requests */
ngx_uint_t malloc_trim_req_count;

ngx_uint_t directive_line;

#if (nginx_version >= 1011011)
/* the following 2 fields are only used by ngx.req.raw_headers() for now */
ngx_buf_t **busy_buf_ptrs;
Expand Down
15 changes: 14 additions & 1 deletion src/ngx_http_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,9 @@ ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
{
u_char *p, *out;
size_t len;
ngx_uint_t start_line;

ngx_http_lua_main_conf_t *lmcf;

len = sizeof("=(:)") - 1 + tag_len + cf->conf_file->file.name.len
+ NGX_INT64_LEN + 1;
Expand All @@ -1328,10 +1331,14 @@ ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,

found:

lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
start_line = lmcf->directive_line > 0
? lmcf->directive_line : cf->conf_file->line;

p = ngx_snprintf(out, len, "=%*s(%*s:%d)%Z",
tag_len, tag, cf->conf_file->file.name.data
+ cf->conf_file->file.name.len - p,
p, cf->conf_file->line);
p, start_line);

*chunkname_len = p - out - 1; /* exclude the trailing '\0' byte */

Expand All @@ -1343,6 +1350,7 @@ ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
char *
ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
{
ngx_http_lua_main_conf_t *lmcf;
ngx_http_lua_block_parser_ctx_t ctx;

int level = 1;
Expand Down Expand Up @@ -1376,6 +1384,9 @@ ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
ctx.token_len = 0;
start_line = cf->conf_file->line;

lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
lmcf->directive_line = start_line;

dd("init start line: %d", (int) start_line);

ctx.start_line = start_line;
Expand Down Expand Up @@ -1494,6 +1505,8 @@ ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)

done:

lmcf->directive_line = 0;

if (rc == NGX_ERROR) {
return NGX_CONF_ERROR;
}
Expand Down
71 changes: 69 additions & 2 deletions t/002-content.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Test::Nginx::Socket::Lua;
repeat_each(2);
#repeat_each(1);

plan tests => repeat_each() * (blocks() * 2 + 24);
plan tests => repeat_each() * (blocks() * 2 + 27);

#no_diff();
#no_long_string();
Expand Down Expand Up @@ -849,4 +849,71 @@ GET /lua
--- response_body_like: 500 Internal Server Error
--- error_code: 500
--- error_log eval
qr/failed to load inlined Lua code: /
qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:40\)/



=== TEST 43: syntax error in content_by_lua_block
--- config
location /lua {

content_by_lua_block {
'for end';
}
}
--- request
GET /lua
--- response_body_like: 500 Internal Server Error
--- error_code: 500
--- error_log eval
qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:41\)/



=== TEST 44: syntax error in second content_by_lua_block
--- config
location /foo {
content_by_lua_block {
'for end';
}
}

location /lua {
content_by_lua_block {
'for end';
}
}
--- request
GET /lua
--- response_body_like: 500 Internal Server Error
--- error_code: 500
--- error_log eval
qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:46\)/



=== TEST 45: syntax error in thrid content_by_lua_block
--- config
location /foo {
content_by_lua_block {
'for end';
}
}

location /bar {
content_by_lua_block {
'for end';
}
}

location /lua {
content_by_lua_block {
'for end';
}
}
--- request
GET /lua
--- response_body_like: 500 Internal Server Error
--- error_code: 500
--- error_log eval
qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:52\)/