when nginx conf like : "if ( $forward = "pre-release" ) {"
func prepareIfArgs(d Directive) Directive {
e := len(d.Args) - 1
if len(d.Args) > 0 && strings.HasPrefix(d.Args[0], "(") && strings.HasSuffix(d.Args[e], ")") {
d.Args[0] = strings.TrimLeftFunc(strings.TrimPrefix(d.Args[0], "("), unicode.IsSpace)
d.Args[e] = strings.TrimRightFunc(strings.TrimSuffix(d.Args[e], ")"), unicode.IsSpace)
if len(d.Args[0]) == 0 { // here d.Args need to minus one
d.Args = d.Args[1:]
}
if len(d.Args[e]) == 0 {
d.Args = d.Args[:e]
}
}
return d
}
or else. program will panic and like this:
panic: runtime error: index out of range [4] with length 4
when nginx conf like : "if ( $forward = "pre-release" ) {" func prepareIfArgs(d Directive) Directive { e := len(d.Args) - 1 if len(d.Args) > 0 && strings.HasPrefix(d.Args[0], "(") && strings.HasSuffix(d.Args[e], ")") { d.Args[0] = strings.TrimLeftFunc(strings.TrimPrefix(d.Args[0], "("), unicode.IsSpace) d.Args[e] = strings.TrimRightFunc(strings.TrimSuffix(d.Args[e], ")"), unicode.IsSpace) if len(d.Args[0]) == 0 { // here d.Args need to minus one d.Args = d.Args[1:] } if len(d.Args[e]) == 0 { d.Args = d.Args[:e] } } return d } or else. program will panic and like this: panic: runtime error: index out of range [4] with length 4
goroutine 1 [running]: github.com/aluttik/go-crossplane.prepareIfArgs(0xc0000bcdee, 0x2, 0x168, 0xc0001e6090, 0x4, 0x7, 0x0, 0x0, 0x0, 0x0, ...) /Users/lixiang/go/pkg/mod/github.com/aluttik/go-crossplane@v0.0.0-20201125234241-e4532485989f/util.go:60 +0x88b github.com/aluttik/go-crossplane.(*parser).parse(0xc000071b08, 0xc0001000a0, 0xc0001020c0, 0xc0001cc3a0, 0x2, 0x2, 0x0, 0x2, 0x0, 0x0, ...)