diff --git a/.golangci.yml b/.golangci.yml index eda17d15..e5e1f8c7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,11 +24,13 @@ linters: - golint - maligned - scopelint + - exhaustruct # deprecated - deadcode - varcheck - structcheck - nosnakecase + - exhaustivestruct # Run options diff --git a/parse.go b/parse.go index cfaa06ba..92cd43c9 100644 --- a/parse.go +++ b/parse.go @@ -252,10 +252,10 @@ func (p *parser) parse(parsing *Config, tokens <-chan NgxToken, ctx blockCtx, co } } for t.IsQuoted || (t.Value != "{" && t.Value != ";" && t.Value != "}") { - if strings.HasPrefix(t.Value, "#") && !t.IsQuoted { - commentsInArgs = append(commentsInArgs, t.Value[1:]) - } else { + if !strings.HasPrefix(t.Value, "#") || t.IsQuoted { stmt.Args = append(stmt.Args, t.Value) + } else if p.options.ParseComments { + commentsInArgs = append(commentsInArgs, t.Value[1:]) } t, tokenOk = <-tokens if !tokenOk { diff --git a/parse_test.go b/parse_test.go index ae23ea23..ad7b691a 100644 --- a/parse_test.go +++ b/parse_test.go @@ -881,6 +881,29 @@ var parseFixtures = []parseFixture{ }, }, }}, + {"comments-between-args-disable-parse", "", ParseOptions{ParseComments: false}, Payload{ + Status: "ok", + Config: []Config{ + { + File: getTestConfigPath("comments-between-args-disable-parse", "nginx.conf"), + Status: "ok", + Parsed: Directives{ + { + Directive: "http", + Args: []string{}, + Line: 1, + Block: Directives{ + { + Directive: "log_format", + Args: []string{"\\#arg\\ 1", "#arg 2"}, + Line: 2, + }, + }, + }, + }, + }, + }, + }}, {"premature-eof", "", ParseOptions{}, Payload{ Status: "failed", Errors: []PayloadError{ diff --git a/testdata/configs/comments-between-args-disable-parse/nginx.conf b/testdata/configs/comments-between-args-disable-parse/nginx.conf new file mode 100644 index 00000000..b26f13d2 --- /dev/null +++ b/testdata/configs/comments-between-args-disable-parse/nginx.conf @@ -0,0 +1,7 @@ +http { #comment 1 + log_format #comment 2 + \#arg\ 1 #comment 3 + '#arg 2' #comment 4 + #comment 5 + ; +} \ No newline at end of file