[GH-ISSUE #1] parser.parseStatement does not follow grammar for parsing parameters #3

Closed
opened 2026-02-28 01:20:27 +03:00 by kerem · 1 comment
Owner

Originally created by @bonnyr on GitHub (May 6, 2020).
Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/1

The grammar outlined in the documentation suggests that parsing directives follows these rules:

directive   : Keyword [parameters] (semicolon|block)
            ;
parameters  : parameters keyword
            ;
keyword     : Keyword 
            | Variable 
            | Regex
            ;

This is implemented in parseStatement and the code iterates over tokens and checks for quoted string or keyword tokens, but not for variables even though the keyword production above clearly indicates Variables are allowed.

This can be easily checked by trying to parse the following fragment:


...
http {
   ...
    map $host $clientname {
        default -;
    }
  ...
}

In this case the parameters are variables and cause panic during parse

Originally created by @bonnyr on GitHub (May 6, 2020). Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/1 The grammar outlined in the documentation suggests that parsing directives follows these rules: ``` directive : Keyword [parameters] (semicolon|block) ; parameters : parameters keyword ; keyword : Keyword | Variable | Regex ; ``` This is implemented in parseStatement and the code iterates over tokens and checks for quoted string or keyword tokens, but not for variables even though the `keyword` production above clearly indicates Variables are allowed. This can be easily checked by trying to parse the following fragment: ``` ... http { ... map $host $clientname { default -; } ... } ``` In this case the parameters are variables and cause panic during parse
kerem 2026-02-28 01:20:27 +03:00
Author
Owner

@tufanbarisyildirim commented on GitHub (May 6, 2020):

Thanks for reporting @bonnyr
Confirmed that it does not accept variables as directive parameter.
I would be happy to review and merge if you have a solution for it. I will also fix when I have time if you don't.

<!-- gh-comment-id:624494723 --> @tufanbarisyildirim commented on GitHub (May 6, 2020): Thanks for reporting @bonnyr Confirmed that it does not accept variables as directive parameter. I would be happy to review and merge if you have a solution for it. I will also fix when I have time if you don't.
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#3
No description provided.