[GH-ISSUE #55] WithCustomDirectives is broken #25

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

Originally created by @nf-brentsaner on GitHub (Nov 7, 2024).
Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/55

Originally assigned to: @tufanbarisyildirim on GitHub.

You never initialize the p.opts.customDirectives map, leading to a panic: assignment to entry in nil map on line 95 of parser/parser.go.

Originally created by @nf-brentsaner on GitHub (Nov 7, 2024). Original GitHub issue: https://github.com/tufanbarisyildirim/gonginx/issues/55 Originally assigned to: @tufanbarisyildirim on GitHub. You never initialize the `p.opts.customDirectives` map, leading to a `panic: assignment to entry in nil map` on line 95 of parser/parser.go.
kerem 2026-02-28 01:20:34 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tufanbarisyildirim commented on GitHub (Nov 15, 2024):

Hi @nf-brentsaner can you please share a bit more like the code you run? I can't reproduce this

<!-- gh-comment-id:2478491247 --> @tufanbarisyildirim commented on GitHub (Nov 15, 2024): Hi @nf-brentsaner can you please share a bit more like the code you run? I can't reproduce this
Author
Owner

@nf-brentsaner commented on GitHub (Nov 15, 2024):

Sure thing. Here's a minimum example demonstrating.

package main

import (
	`log`

	"github.com/tufanbarisyildirim/gonginx/parser"
)

func main() {

	var err error
	var ngxParser *parser.Parser

	if ngxParser, err = parser.NewParser(
		"/etc/nginx/nginx.conf",
		parser.WithDefaultOptions(),
		parser.WithIncludeParsing(),
		parser.WithCustomDirectives(
			"foo",
			"foo_bar",
			"foo_bar_baz",
		),
	); err != nil {
		log.Panicln(err)
	}

	_ = ngxParser
}

Here's the version I have imported for it:

$ grep -F gonginx go.mod 
require github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8

(which should be current default HEAD)

And here's the panic:

$ go run main.go 
panic: assignment to entry in nil map

goroutine 1 [running]:
main.main.WithCustomDirectives.func3(0xc0000ce410)
	/opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:95 +0x70
github.com/tufanbarisyildirim/gonginx/parser.NewParserFromLexer(0xc0000b4240, {0xc0000caec0, 0x4, 0xc000000000?})
	/opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:145 +0x162
github.com/tufanbarisyildirim/gonginx/parser.NewParser({0x4cc8e3, 0x15}, {0xc0000caec0, 0x4, 0x4})
	/opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:129 +0x2ce
main.main()
	/tmp/testgo/main.go:14 +0xf4
exit status 2
<!-- gh-comment-id:2479386214 --> @nf-brentsaner commented on GitHub (Nov 15, 2024): Sure thing. Here's a minimum example demonstrating. ```go package main import ( `log` "github.com/tufanbarisyildirim/gonginx/parser" ) func main() { var err error var ngxParser *parser.Parser if ngxParser, err = parser.NewParser( "/etc/nginx/nginx.conf", parser.WithDefaultOptions(), parser.WithIncludeParsing(), parser.WithCustomDirectives( "foo", "foo_bar", "foo_bar_baz", ), ); err != nil { log.Panicln(err) } _ = ngxParser } ``` Here's the version I have imported for it: ``` $ grep -F gonginx go.mod require github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8 ``` (which should be current default `HEAD`) And here's the panic: ``` $ go run main.go panic: assignment to entry in nil map goroutine 1 [running]: main.main.WithCustomDirectives.func3(0xc0000ce410) /opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:95 +0x70 github.com/tufanbarisyildirim/gonginx/parser.NewParserFromLexer(0xc0000b4240, {0xc0000caec0, 0x4, 0xc000000000?}) /opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:145 +0x162 github.com/tufanbarisyildirim/gonginx/parser.NewParser({0x4cc8e3, 0x15}, {0xc0000caec0, 0x4, 0x4}) /opt/dev/go/pkg/mod/github.com/tufanbarisyildirim/gonginx@v0.0.0-20241013191809-e73b7dd454e8/parser/parser.go:129 +0x2ce main.main() /tmp/testgo/main.go:14 +0xf4 exit status 2 ```
Author
Owner

@tufanbarisyildirim commented on GitHub (Nov 15, 2024):

please remove parser.WithDefaultOptions() it will work for you with no issue and I'm taking care of it now. good catch!

<!-- gh-comment-id:2479616572 --> @tufanbarisyildirim commented on GitHub (Nov 15, 2024): please remove `parser.WithDefaultOptions()` it will work for you with no issue and I'm taking care of it now. good catch!
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#25
No description provided.