mirror of https://github.com/caddyserver/caddy.git
Fix snippet nesting bug
This commit is contained in:
parent
fa334c4bdf
commit
b2aa679c33
|
@ -459,23 +459,22 @@ func (p *parser) snippetTokens() ([]Token, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
count := 1
|
nesting := 1 // count our own nesting in snippets
|
||||||
tokens := []Token{}
|
tokens := []Token{}
|
||||||
for p.Next() {
|
for p.Next() {
|
||||||
if p.Val() == "}" {
|
if p.Val() == "}" {
|
||||||
count--
|
nesting--
|
||||||
if count == 0 {
|
if nesting == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p.Val() == "{" {
|
if p.Val() == "{" {
|
||||||
p.nesting++
|
nesting++
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
tokens = append(tokens, p.tokens[p.cursor])
|
tokens = append(tokens, p.tokens[p.cursor])
|
||||||
}
|
}
|
||||||
// make sure we're matched up
|
// make sure we're matched up
|
||||||
if count != 0 {
|
if nesting != 0 {
|
||||||
return nil, p.SyntaxErr("}")
|
return nil, p.SyntaxErr("}")
|
||||||
}
|
}
|
||||||
return tokens, nil
|
return tokens, nil
|
||||||
|
|
Loading…
Reference in New Issue