variable shadowing of token (#503)
* Added test for $INCLUDE statement parser in zone files * FIX: localized l to switch statement, shadowed later call to os.Open(l.token)
This commit is contained in:
parent
0f3adef2e2
commit
bbca4873b3
3
scan.go
3
scan.go
|
@ -278,8 +278,7 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
neworigin := origin // There may be optionally a new origin set after the filename, if not use current one
|
neworigin := origin // There may be optionally a new origin set after the filename, if not use current one
|
||||||
l := <-c
|
switch l := <-c; l.value {
|
||||||
switch l.value {
|
|
||||||
case zBlank:
|
case zBlank:
|
||||||
l := <-c
|
l := <-c
|
||||||
if l.value == zString {
|
if l.value == zString {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseZoneInclude(t *testing.T) {
|
||||||
|
|
||||||
|
tmpfile, err := ioutil.TempFile("", "dns")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not create tmpfile for test: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tmpfile.WriteString("foo\tIN\tA\t127.0.0.1"); err != nil {
|
||||||
|
t.Fatalf("unable to write content to tmpfile %q: %s", tmpfile.Name(), err)
|
||||||
|
}
|
||||||
|
if err := tmpfile.Close(); err != nil {
|
||||||
|
t.Fatalf("could not close tmpfile %q: %s", tmpfile.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
zone := "$INCLUDE " + tmpfile.Name()
|
||||||
|
|
||||||
|
tok := ParseZone(strings.NewReader(zone), "", "")
|
||||||
|
for x := range tok {
|
||||||
|
if x.Error != nil {
|
||||||
|
t.Fatalf("expected no error, but got %s", x.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Remove(tmpfile.Name())
|
||||||
|
|
||||||
|
tok = ParseZone(strings.NewReader(zone), "", "")
|
||||||
|
for x := range tok {
|
||||||
|
if x.Error == nil {
|
||||||
|
t.Fatalf("expected first token to contain an error but it didn't")
|
||||||
|
}
|
||||||
|
if !strings.Contains(x.Error.Error(), "failed to open") ||
|
||||||
|
!strings.Contains(x.Error.Error(), tmpfile.Name()) {
|
||||||
|
t.Fatalf(`expected error to contain: "failed to open" and %q but got: %s`, tmpfile.Name(), x.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue