From d56a9a1c5dcbfa3191de905884c7016feb168936 Mon Sep 17 00:00:00 2001 From: Radim Marek Date: Sun, 6 Dec 2015 23:49:21 +0100 Subject: [PATCH] Correct position of the newly imported tokens --- caddy/parse/parsing.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/caddy/parse/parsing.go b/caddy/parse/parsing.go index 8aa711c3..e011fd8c 100644 --- a/caddy/parse/parsing.go +++ b/caddy/parse/parsing.go @@ -198,12 +198,23 @@ func (p *parser) doImport() error { return p.Errf("No files matching the import pattern %s", importPattern) } + // Splice out the import directive and its argument (2 tokens total) + // and insert the imported tokens in their place. + tokensBefore := p.tokens[:p.cursor-1] + tokensAfter := p.tokens[p.cursor+1:] + // cursor was advanced one position to read filename; rewind it + p.cursor-- + + p.tokens = tokensBefore + for _, importFile := range matches { if err := p.doSingleImport(importFile); err != nil { return err } } + p.tokens = append(p.tokens, append(tokensAfter)...) + return nil } @@ -222,10 +233,7 @@ func (p *parser) doSingleImport(importFile string) error { // Splice out the import directive and its argument (2 tokens total) // and insert the imported tokens in their place. - tokensBefore := p.tokens[:p.cursor-1] - tokensAfter := p.tokens[p.cursor+1:] - p.tokens = append(tokensBefore, append(importedTokens, tokensAfter...)...) - p.cursor-- // cursor was advanced one position to read the filename; rewind it + p.tokens = append(p.tokens, append(importedTokens)...) return nil }