Parsing TXT records now works OK

This commit is contained in:
Miek Gieben 2012-02-12 22:24:18 +01:00
parent 6279bb1917
commit a7b2a88e7a
3 changed files with 65 additions and 57 deletions

View File

@ -206,8 +206,9 @@ func TestQuotes(t *testing.T) {
`t.example.com. IN TXT "abc" "DEF"`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
`t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
`t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa \"",
`t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaaaaa\"",
// `t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
`t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
`t.example.com. IN TXT aaa aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
`t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.":
// "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.":

View File

@ -10,7 +10,7 @@ import (
)
// Only used when debugging the parser itself.
var _DEBUG = true
var _DEBUG = false
// Complete unsure about the correctness of this value?
// Large blobs of base64 code might get longer than this....
@ -237,7 +237,7 @@ func parseZone(r io.Reader, f string, t chan Token, include int) {
if !IsFqdn(l.token) {
origin = l.token + "." + origin // Append old origin if the new one isn't a fqdn
} else {
origin = "." +l.token
origin = "." + l.token
}
st = _EXPECT_OWNER_DIR
case _EXPECT_OWNER_BL:
@ -347,6 +347,8 @@ func (l lex) String() string {
return "S:" + l.token + "$"
case _BLANK:
return "_"
case _QUOTE:
return "\""
case _NEWLINE:
return "|\n"
case _RRTYPE:
@ -450,6 +452,12 @@ func zlexer(s scanner.Scanner, c chan lex) {
stri++
break
}
if stri > 0 {
l.value = _STRING
l.token = string(str[:stri])
c <- l
stri = 0
}
commt = true
case '\n':
// Hmmm, escape newline
@ -533,7 +541,7 @@ func zlexer(s scanner.Scanner, c chan lex) {
if stri != 0 {
l.value = _STRING
l.token = string(str[:stri])
c <-l
c <- l
stri = 0
}
l.value = _QUOTE

View File

@ -709,28 +709,17 @@ func setTXT(h RR_Header, c chan lex, f string) (RR, *ParseError) {
// Get the remaining data until we see a NEWLINE
quote := false
quoted := false // unquoted strings are also allowed
l := <-c
i := 0
s := make([]string, i)
if l.value == _QUOTE {
quoted = true
}
var s []string
switch l.value == _QUOTE {
case true: // A number of quoted string
s = make([]string, 0)
for l.value != _NEWLINE && l.value != _EOF {
switch l.value {
case _STRING:
s = append(s, l.token)
i++
case _BLANK:
if !quoted {
if i = 0 {
return nil, &ParseError{f, "bad TXT txt", l}
}
s[i-1] += l.token
l = <-c
continue
}
if quoted && quote {
if quote {
// _BLANK can only be seen in between txt parts.
return nil, &ParseError{f, "bad TXT Txt", l}
}
@ -741,6 +730,16 @@ func setTXT(h RR_Header, c chan lex, f string) (RR, *ParseError) {
}
l = <-c
}
if quote {
return nil, &ParseError{f, "Bad TXT Txt", l}
}
case false: // Unquoted text record
s = make([]string, 1)
for l.value != _NEWLINE && l.value != _EOF {
s[0] += l.token
l = <-c
}
}
rr.Txt = s
return rr, nil
}