From 69f7cb47b84a110f9e4901af9ee2cfdba8451fb7 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 12 Nov 2018 15:38:43 +0100 Subject: [PATCH] remove trim() on comments (to keep comment indentation) --- internal/cnf/parser/nginx/decoder.go | 4 ++-- internal/cnf/parser/nginx/decoder_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/cnf/parser/nginx/decoder.go b/internal/cnf/parser/nginx/decoder.go index beb2e31..9030c74 100644 --- a/internal/cnf/parser/nginx/decoder.go +++ b/internal/cnf/parser/nginx/decoder.go @@ -74,10 +74,10 @@ func (d *decoder) Decode(v interface{}) error { // 2. comment if line[0] == '#' { l.Type = COMMENT - l.Components = []string{strings.Trim(line[1:], " \t")} + l.Components = []string{line[1:]} } else if line[0] == ';' { l.Type = COLONCOMMENT - l.Components = []string{strings.Trim(line[1:], " \t")} + l.Components = []string{line[1:]} } else if line[0] == '}' { l.Type = SECTIONEND if len(stack) < 1 { diff --git a/internal/cnf/parser/nginx/decoder_test.go b/internal/cnf/parser/nginx/decoder_test.go index 8a3b056..c391b68 100644 --- a/internal/cnf/parser/nginx/decoder_test.go +++ b/internal/cnf/parser/nginx/decoder_test.go @@ -39,16 +39,16 @@ func TestEachLineType(t *testing.T) { {"#some comment\n", []string{"some comment"}, COMMENT}, {"#some\tcomment\n", []string{"some\tcomment"}, COMMENT}, - {"# some comment \n", []string{"some comment"}, COMMENT}, - {"# some comment \t\n", []string{"some comment"}, COMMENT}, - {"\t# some comment {\n", []string{"some comment {"}, COMMENT}, + {"# some comment \n", []string{" some comment"}, COMMENT}, + {"# some comment \t\n", []string{" some comment"}, COMMENT}, + {"\t# some comment {\n", []string{" some comment {"}, COMMENT}, {";some comment\n", []string{"some comment"}, COLONCOMMENT}, - {"; some\tcomment\n", []string{"some\tcomment"}, COLONCOMMENT}, - {"; some comment\n", []string{"some comment"}, COLONCOMMENT}, - {"; some comment \n", []string{"some comment"}, COLONCOMMENT}, - {"; some comment \t\n", []string{"some comment"}, COLONCOMMENT}, - {"\t; some comment {\n", []string{"some comment {"}, COLONCOMMENT}, + {"; some\tcomment\n", []string{" some\tcomment"}, COLONCOMMENT}, + {"; some comment\n", []string{" some comment"}, COLONCOMMENT}, + {"; some comment \n", []string{" some comment"}, COLONCOMMENT}, + {"; some comment \t\n", []string{" some comment"}, COLONCOMMENT}, + {"\t; some comment {\n", []string{" some comment {"}, COLONCOMMENT}, } for i, test := range tests {