[GH-ISSUE #13] Painc casued by parsing config which contained lua block #5

Closed
opened 2026-02-28 01:20:28 +03:00 by kerem · 2 comments
Owner

Originally created by @caiwc on GitHub (Mar 18, 2023).
Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/13

Part of my nginx config:

http {
    lua_package_path "/usr/local/nginx/test/lib/?.lua;;";
    lua_shared_dict tracing_buffer 100m;
    init_by_lua_block {
        require "resty.core"
        collectgarbage("collect")
    }

   server {
      listen       80;
      #  some route rules .... 
  }
}

My code:

p, err := parser.NewParser("/Users/caiweicheng/Downloads/conf/nginx.conf")
if err != nil {
    return err
}
return p.Parse()

Full error:

panic: unexpected token BlockEnd (}) on line 27, column 5

goroutine 1 [running]:
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x3, 0x14000124150)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:227 +0xaac
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x14000124138)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:220 +0x6c0
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x140001240e0)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:220 +0x6c0
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2c)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4
github.com/tufanbarisyildirim/gonginx/parser.(*Parser).Parse(...)
        /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:147
main.parseNginx(0x14000102058, 0x14000102000)
        /Users/username/go-project/awesomeProject/nginxparse/main.go:17 +0x74
main.main()

I found out that this error is due to the fact that each line of the lua block does not need to end with a semicolon. But when NewParser judges the end of the block, it must end with a semicolon.

What did you expect to see?

At least parse nginx config not painc.
I have two thoughts:

  • First,NewParser handles lua modules specially, and supports no semicolon ending;
  • Second, all block parsing can support not ending with a semicolon.
Originally created by @caiwc on GitHub (Mar 18, 2023). Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/13 Part of my nginx config: ``` http { lua_package_path "/usr/local/nginx/test/lib/?.lua;;"; lua_shared_dict tracing_buffer 100m; init_by_lua_block { require "resty.core" collectgarbage("collect") } server { listen 80; # some route rules .... } } ``` My code: ``` p, err := parser.NewParser("/Users/caiweicheng/Downloads/conf/nginx.conf") if err != nil { return err } return p.Parse() ``` Full error: ``` panic: unexpected token BlockEnd (}) on line 27, column 5 goroutine 1 [running]: github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x3, 0x14000124150) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:227 +0xaac github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4 github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x14000124138) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:220 +0x6c0 github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4 github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseStatement(0x14000132000, 0x5, 0x140001240e0) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:220 +0x6c0 github.com/tufanbarisyildirim/gonginx/parser.(*Parser).parseBlock(0x14000132000, 0x2c) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:165 +0xc4 github.com/tufanbarisyildirim/gonginx/parser.(*Parser).Parse(...) /Users/username/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20230104065106-9ae864d29eed/parser/parser.go:147 main.parseNginx(0x14000102058, 0x14000102000) /Users/username/go-project/awesomeProject/nginxparse/main.go:17 +0x74 main.main() ``` I found out that this error is due to the fact that each line of the lua block does not need to end with a semicolon. But when `NewParser` judges the end of the block, it must end with a semicolon. ### What did you expect to see? At least parse nginx config not painc. I have two thoughts: - First,`NewParser` handles lua modules specially, and supports no semicolon ending; - Second, all block parsing can support not ending with a semicolon.
kerem closed this issue 2026-02-28 01:20:28 +03:00
Author
Owner

@caiwc commented on GitHub (Mar 18, 2023):

It turns out that there are already PR #5 trying to fix this problem

<!-- gh-comment-id:1474791374 --> @caiwc commented on GitHub (Mar 18, 2023): It turns out that there are already PR #5 trying to fix this problem
Author
Owner

@tufanbarisyildirim commented on GitHub (Mar 25, 2023):

I'm glad thats solved.

<!-- gh-comment-id:1483761848 --> @tufanbarisyildirim commented on GitHub (Mar 25, 2023): I'm glad thats solved.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/gonginx#5
No description provided.